Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Websockets upgrade request: HTTP 431: Request Header Fields Too Large with big cookies #2267

Open
1 task done
DomasM opened this issue Mar 14, 2024 · 11 comments
Open
1 task done
Labels

Comments

@DomasM
Copy link

DomasM commented Mar 14, 2024

Environment

  • VerneMQ Version: vernemq/vernemq:latest
  • OS: docker debian:11-slim
  • Erlang/OTP version (if building from source):
  • Cluster size/standalone: standalone

Current Behavior

I am trying to connect to verne broker from the browser via websocket using mqtt.js. Cookies are added to the Upgrade request by the browser, and these cookies are large. Connection attempt is refused with HTTP error 431. Once I delete the cookies via browser dev tools, connection succeeds.

Expected behaviour

  • Connection succeeds regardless of the cookie size, OR
  • Behavior and limit configuration is documented here

Configuration, logs, error output, etc.

verne config:

services:
  vernemq:
    image: vernemq/vernemq
    container_name: vernemq
    environment:
      - DOCKER_VERNEMQ_ACCEPT_EULA=yes
      - DOCKER_VERNEMQ_ALLOW_ANONYMOUS=on
    ports:
      - "1883:1883"
      - "8080:8080"
    restart: unless-stopped



request:

curl "ws://localhost:8080/mqtt" -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:123.0) Gecko/20100101 Firefox/123.0" -H "Accept: */*" -H "Accept-Language: en-US,en;q=0.5" -H "Accept-Encoding: gzip, deflate, br" -H "Sec-WebSocket-Version: 13" -H "Origin: http://localhost:5173" -H "Sec-WebSocket-Protocol: mqtt" -H "Sec-WebSocket-Extensions: permessage-deflate" -H "Sec-WebSocket-Key: sVLbEJyDhg7SuzDBjLWksQ==" -H "Connection: keep-alive, Upgrade" -H "Cookie: .AspNetCore.Cookies=chunks-2; .AspNetCore.CookiesC1=CfDJ8GvEDUoW6SJBqGmcn6iBgKXnzqDL03AnFNEfL7kbI_zuDmOi_0QTknU3zqBmN4wFoWFhoFS2T9SvqdSBl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UtyA5xfwMau5MpGoM2s6zoHgZDWOE31Xi2lxnD4vDTxGVpbGyLdZravqQHzYewjYmLkWoWJp6bS3wpqfyL3TcLJuesXR9mEilLCv0dtpV_rkS_-WPVStVUuALeuS71JnMbRZZWuPtTYL4I27syLcZv48Jwyi16keWlfvQfS1g5ePLxhm2aI-Wi5FWK9yp2HMab2B8b5uExQ3Omr1vDPatEY0aUQZKaRhrQYg" -H "Sec-Fetch-Dest: empty" -H "Sec-Fetch-Mode: websocket" -H "Sec-Fetch-Site: same-site" -H "Pragma: no-cache" -H "Cache-Control: no-cache" -H "Upgrade: websocket"


response:

HTTP/1.1 431 Request Header Fields Too Large
connection: close
content-length: 0

Code of Conduct

  • I agree to follow the VerneMQ's Code of Conduct
@DomasM DomasM added the bug label Mar 14, 2024
@DomasM DomasM changed the title [Bug]: HTTP 431: Request Header Fields Too Large with big cookies [Bug]: Websockets upgrade request: HTTP 431: Request Header Fields Too Large with big cookies Mar 14, 2024
@ioolkos
Copy link
Contributor

ioolkos commented Mar 14, 2024

@DomasM Thanks. Can you try setting max_request_line_length in vernemq.conf?

listener.tcp.default.max_request_line_length=16500 (whatever length you might seem to need)
Set this for your named listener where you'll need it. (adapt default to your listener name)


👉 Thank you for supporting VerneMQ: https://github.com/sponsors/vernemq
👉 Using the binary VerneMQ packages commercially (.deb/.rpm/Docker) requires a paid subscription.

@DomasM
Copy link
Author

DomasM commented Mar 15, 2024

@ioolkos Thank you for help. I'm not sure what's my listener name, but anyway vernemq would not start with such setting, saying that it does not exist and suggesting listener.http.default.max_request_line_length, which I tried but it seems that did not change anything in actual behaviour, i.e. still 431.

vernemq  | 2024-03-15T11:42:36.795012+00:00 [error] You've tried to set listener.tcp.default.max_request_line_length, but there is no setting with that name.
vernemq  | 2024-03-15T11:42:36.795098+00:00 [error] Did you mean one of these?
vernemq  | 2024-03-15T11:42:36.891103+00:00 [error] listener.http.$name.max_request_line_length
vernemq  | 2024-03-15T11:42:36.891199+00:00 [error] listener.https.$name.max_request_line_length
vernemq  | 2024-03-15T11:42:36.891270+00:00 [error] listener.tcp.$name.max_connection_lifetime
vernemq  | 2024-03-15T11:42:36.893026+00:00 [error] Error generating configuration in phase transform_datatypes
vernemq  | 2024-03-15T11:42:36.893124+00:00 [error] Conf file attempted to set unknown variable: listener.tcp.default.max_request_line_length
vernemq exited with code 0

@ioolkos
Copy link
Contributor

ioolkos commented Mar 15, 2024

@DomasM Thanks a lot for testing!
The config is obviously only for HTTP listeners, sorry about that.
There's additional options for Cowboy/Ranch connections:
https://github.com/ninenines/cowboy/blob/3ea8395eb8f53a57acb5d3c00b99c70296e7cdbd/doc/src/manual/cowboy_http.asciidoc#L31
Those are currently not exposed in the vernemq.conf file like max_request_line_length.

A workaround is to update the max_header_value_length option dynamically in a VerneMQ shell. (sudo vernemq attach, when done detach with ctrl+g and then at the user switch q).
Example for a HTTP listener running on 127.0.0.1:8888. The listener does not have to be restarted, it is updated live:

Opts = ranch:get_protocol_options({{127,0,0,1}, 8888}).
NewOpts = maps:put(max_header_value_length, 8192, Opts).
ranch:set_protocol_options({{127,0,0,1}, 8888}, NewOpts).

You could at least use this to test whether this really is about that specific setting. The default value for max_header_value_length is 4096.


👉 Thank you for supporting VerneMQ: https://github.com/sponsors/vernemq
👉 Using the binary VerneMQ packages commercially (.deb/.rpm/Docker) requires a paid subscription.

@DomasM
Copy link
Author

DomasM commented Mar 15, 2024

@ioolkos Thank you again. I tried as suggested and while setting cowboy options seems to work, further requests still end with 431.
Additionally, as you can see initial max_header_value_length is 8192, while my cookie size is about 6700, so it should still pass?
https://github.com/ninenines/cowboy/blob/3ea8395eb8f53a57acb5d3c00b99c70296e7cdbd/src/cowboy_http.erl#L677

Opts = ranch:get_protocol_options({{127,0,0,1}, 8888}).
#{connection_type => supervisor,
  env =>
      #{dispatch =>
            [{'_',[],
                  [{[<<"metrics">>],[],vmq_metrics_http,[]},
                   {[<<"api">>,<<"v1">>,'...'],[],vmq_http_mgmt_api,[]},
                   {[<<"status.json">>],[],vmq_status_http,[]},
                   {[<<"status">>],
                    [],cowboy_static,
                    {priv_file,vmq_server,"static/index.html"}},
                   {[<<"status">>,'...'],
                    [],cowboy_static,
                    {priv_dir,vmq_server,"static"}},
                   {[<<"health">>],[],vmq_health_http,[]},
                   {[<<"api">>,<<"v2">>,command],[],vmq_http_v2_api,[]},
                   {[<<"restmqtt">>,<<"api">>,<<"v1">>,<<"publish">>],
                    [],vmq_http_pub,
                    [{publish_fun,#Fun<vmq_reg.17.40855500>}]}]}]},
  max_header_value_length => 8192,
  opts =>
      [{max_connections,10000},
       {nr_of_acceptors,10},
       {config_mod,vmq_http_config},
       {config_fun,config},
       {max_request_line_length,63000},
       {http_modules,"[]"},
       {listener_name,"default"},
       {proxy_protocol,false}]}
(VerneMQ@192.168.16.2)2> NewOpts = maps:put(max_header_value_length, 62999, Opts).
#{connection_type => supervisor,
  env =>
      #{dispatch =>
            [{'_',[],
                  [{[<<"metrics">>],[],vmq_metrics_http,[]},
                   {[<<"api">>,<<"v1">>,'...'],[],vmq_http_mgmt_api,[]},
                   {[<<"status.json">>],[],vmq_status_http,[]},
                   {[<<"status">>],
                    [],cowboy_static,
                    {priv_file,vmq_server,"static/index.html"}},
                   {[<<"status">>,'...'],
                    [],cowboy_static,
                    {priv_dir,vmq_server,"static"}},
                   {[<<"health">>],[],vmq_health_http,[]},
                   {[<<"api">>,<<"v2">>,command],[],vmq_http_v2_api,[]},
                   {[<<"restmqtt">>,<<"api">>,<<"v1">>,<<"publish">>],
                    [],vmq_http_pub,
                    [{publish_fun,#Fun<vmq_reg.17.40855500>}]}]}]},
  max_header_value_length => 62999,
  opts =>
      [{max_connections,10000},
       {nr_of_acceptors,10},
       {config_mod,vmq_http_config},
       {config_fun,config},
       {max_request_line_length,63000},
       {http_modules,"[]"},
       {listener_name,"default"},
       {proxy_protocol,false}]}
(VerneMQ@192.168.16.2)3> ranch:set_protocol_options({{127,0,0,1}, 8888}, NewOpts).
ok
Opts2 = ranch:get_protocol_options({{127,0,0,1}, 8888}).
#{connection_type => supervisor,
  env =>
      #{dispatch =>
            [{'_',[],
                  [{[<<"metrics">>],[],vmq_metrics_http,[]},
                   {[<<"api">>,<<"v1">>,'...'],[],vmq_http_mgmt_api,[]},
                   {[<<"status.json">>],[],vmq_status_http,[]},
                   {[<<"status">>],
                    [],cowboy_static,
                    {priv_file,vmq_server,"static/index.html"}},
                   {[<<"status">>,'...'],
                    [],cowboy_static,
                    {priv_dir,vmq_server,"static"}},
                   {[<<"health">>],[],vmq_health_http,[]},
                   {[<<"api">>,<<"v2">>,command],[],vmq_http_v2_api,[]},
                   {[<<"restmqtt">>,<<"api">>,<<"v1">>,<<"publish">>],
                    [],vmq_http_pub,
                    [{publish_fun,#Fun<vmq_reg.17.40855500>}]}]}]},
  max_header_value_length => 62999,
  opts =>
      [{max_connections,10000},
       {nr_of_acceptors,10},
       {config_mod,vmq_http_config},
       {config_fun,config},
       {max_request_line_length,63000},
       {http_modules,"[]"},
       {listener_name,"default"},
       {proxy_protocol,false}]}

@ioolkos
Copy link
Contributor

ioolkos commented Mar 15, 2024

Hm, okay. What listeners do you have running (vmq-admin listener show), and is port 8888 really where you have that listener running?


👉 Thank you for supporting VerneMQ: https://github.com/sponsors/vernemq
👉 Using the binary VerneMQ packages commercially (.deb/.rpm/Docker) requires a paid subscription.

@DomasM
Copy link
Author

DomasM commented Mar 15, 2024

I suppose. Tried setting cowboy options for 8080, but it complained.

Opts = ranch:get_protocol_options({{127,0,0,1}, 8080}).
** exception error: bad argument
     in function  ets:lookup_element/3
        called as ets:lookup_element(ranch_server,{proto_opts,{{127,0,0,1},8080}},2)
        *** argument 2: not a key that exists in the table
     in call from ranch_server:get_protocol_options/1 (/opt/vernemq/_build/default/lib/ranch/src/ranch_server.erl, line 168)
$ vmq-admin listener show
+--------+---------+--------------+-------+------------+-----------+--------------+-----------+
| type   | status  | address      | port  | mountpoint | max_conns | active_conns | all_conns |
+--------+---------+--------------+-------+------------+-----------+--------------+-----------+
| http   | running | 127.0.0.1    | 8888  |            | 10000     | 0            | 0         |
+--------+---------+--------------+-------+------------+-----------+--------------+-----------+
| mqtt   | running | 192.168.16.2 | 1883  |            | 10000     | 4            | 4         |
+--------+---------+--------------+-------+------------+-----------+--------------+-----------+
| mqttws | running | 192.168.16.2 | 8080  |            | 10000     | 0            | 0         |
+--------+---------+--------------+-------+------------+-----------+--------------+-----------+
| http   | running | 192.168.16.2 | 8888  |            | 10000     | 0            | 0         |
+--------+---------+--------------+-------+------------+-----------+--------------+-----------+
| vmq    | running | 192.168.16.2 | 44053 |            | 10000     | 0            | 0         |
+--------+---------+--------------+-------+------------+-----------+--------------+-----------+

@ioolkos
Copy link
Contributor

ioolkos commented Mar 15, 2024

You don't have a listener {{127,0,0,1}, 8080}, you have {{192,168,16,2}, 8080}.


👉 Thank you for supporting VerneMQ: https://github.com/sponsors/vernemq
👉 Using the binary VerneMQ packages commercially (.deb/.rpm/Docker) requires a paid subscription.

@ioolkos
Copy link
Contributor

ioolkos commented Mar 18, 2024

@DomasM were you able to make this work?

Do you think we should expose the max_header_value_length in vernemq.conf? or to re-word the question: do you think the cookie size you used here should be within a "normal" size window?


👉 Thank you for supporting VerneMQ: https://github.com/sponsors/vernemq
👉 Using the binary VerneMQ packages commercially (.deb/.rpm/Docker) requires a paid subscription.

@DomasM
Copy link
Author

DomasM commented Mar 18, 2024 via email

@DomasM
Copy link
Author

DomasM commented Mar 19, 2024

@ioolkos I finally got it working by setting max_header_value_length for the correct listener. IP address of the listener changes from run to run, so the steps current solution is:

  1. Modify vernemq.conf file with listener.http.default.max_request_line_length=63000
  2. Run vernemq
  3. Run vmq-admin listener show and notice which ip address and port is used for mqttws listener
  4. Set options for cowboy/ranch with these IP address and port values.
Address = {192,168,32,2}.
Port = 8080.
Opts = ranch:get_protocol_options({Address, Port}).
NewOpts = maps:put(max_header_value_length, 62999, Opts).
ranch:set_protocol_options({Address, Port}, NewOpts).

To have this working more properly maybe some copy-paste from #2161 would be enough to map max_header_value_length property too?

@ioolkos
Copy link
Contributor

ioolkos commented Mar 19, 2024

@DomasM yes, same approach. In addition, we'd likely need to grab and apply the setting in vmq_ranch_config module where we set the protocol_opts.


👉 Thank you for supporting VerneMQ: https://github.com/sponsors/vernemq
👉 Using the binary VerneMQ packages commercially (.deb/.rpm/Docker) requires a paid subscription.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants