0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 20:30:23 +00:00
Commit graph

281 commits

Author SHA1 Message Date
Viktor Söderqvist
42d87dd776
Add 'max_cancel_stream_rate' config for the rapid reset attack
Co-authored-by: Björn Svensson <bjorn.a.svensson@est.tech>
2023-12-06 12:41:58 +01:00
Loïc Hoguin
22adc4de51
Fix Ranch link in user guide 2023-05-02 11:20:02 +02:00
Loïc Hoguin
9e600f6c1d
Cowboy 2.10.0 2023-04-28 10:41:18 +02:00
Loïc Hoguin
04ca4c5d31
Cowboy 2.9.0 2021-05-12 10:24:40 +02:00
Loïc Hoguin
136e74fc51
Two more HTTP specs 2021-04-24 16:31:29 +02:00
Martin Björklund
8795233c57
AcceptCallback may now return created/see_other tuples for POST
They replace and deprecate the {true,URI} return value.
2020-11-27 16:17:43 +01:00
Viktor Söderqvist
059d58d39f
Graceful shutdown
Note: This commit makes cowboy depend on cowlib master.

Graceful shutdown for HTTP/2:

1. A GOAWAY frame with the last stream id set to 2^31-1 is sent and a
   timer is started (goaway_initial_timeout, default 1000ms), to wait
   for any in-flight requests sent by the client, and the status is set
   to 'closing_initiated'. If the client responds with GOAWAY and closes
   the connection, we're done.
2. A second GOAWAY frame is sent with the actual last stream id and the
   status is set to 'closing'. If no streams exist, the connection
   terminates. Otherwise a second timer (goaway_complete_timeout,
   default 3000ms) is started, to wait for the streams to complete. New
   streams are not accepted when status is 'closing'.
3. If all streams haven't completed after the second timeout, the
   connection is forcefully terminated.

Graceful shutdown for HTTP/1.x:

1. If a request is currently being handled, it is waited for and the
   response is sent back to the client with the header "Connection:
   close". Then, the connection is closed.
2. If the current request handler is not finished within the time
   configured in transport option 'shutdown' (default 5000ms), the
   connection process is killed by its supervisor (ranch).

Implemented for HTTP/1.x and HTTP/2 in the following scenarios:

* When receiving exit signal 'shutdown' from the supervisor (e.g. when
  cowboy:stop_listener/3 is called).
* When a connection process is requested to terminate using
  sys:terminate/2,3.

LH: Edited tests a bit and added todos for useful tests to add.
2020-11-27 15:38:21 +01:00
Thomas Sciaroni
70d393caad
Minor grammar corrections
Verb agreement error "The request process executes
middlewares which, by default, including the router
and then the execution of handlers." -> "The request
process executes middlewares. By default, the request
process executes the router and then the handlers."

Adverbial clause at beginning of sentence needs comma
"By default Cowboy comes..." -> "By default, Cowboy comes..."
2020-08-19 14:37:50 +02:00
Loïc Hoguin
5aac00d60c
Tweak a sentence in the guide
Thanks Tamir Halperin for pointing this out.

[skip ci]
2020-07-01 13:55:58 +02:00
Loïc Hoguin
de955079f9
Fix the cowboy_req:inform/3 example in the manual 2020-05-28 21:07:20 +02:00
Loïc Hoguin
8d5628c5f1
Cowboy 2.8.0 2020-05-21 19:02:12 +02:00
Loïc Hoguin
8337aca4d3
Increase the default max_keepalive HTTP option to 1000
100 is very low for current deployments. 1000 is more
appropriate as a default value.
2020-05-20 11:08:58 +02:00
Loïc Hoguin
78b23ddfa5
Clarify the routing algorithm 2020-05-20 10:53:52 +02:00
Loïc Hoguin
8af3216c4c
Document the HTTP/2 linger_timeout option 2020-04-08 10:27:45 +02:00
Loïc Hoguin
f58189df19
Clarify that protocol opts may be defined by stream handlers 2020-04-08 10:27:14 +02:00
Loïc Hoguin
0fc33c5300
Add more headers to cowboy_req:parse_header/2,3 2020-03-30 15:02:35 +02:00
Loïc Hoguin
6ad842a742
Increase the default max_received_frame_rate
Allow 10000 frames every 10 seconds instead of just 1000,
as the limit was too quickly reached in some deployments.
2020-03-29 13:51:21 +02:00
Loïc Hoguin
f8e94c3315
Add more specifications 2020-03-29 13:22:06 +02:00
Loïc Hoguin
2ea1313763
Add Trace Context to the list of specs 2020-02-08 15:32:46 +01:00
Loïc Hoguin
3ec0cd8b8d
Clarify modifying/adding to the Req object 2020-02-08 15:32:46 +01:00
Loïc Hoguin
edea415da8
Fix cowboy_req:parse_header manual for unknown headers 2020-01-06 14:42:24 +01:00
Loïc Hoguin
5e0be061bb
Add a skeleton performance chapter to the guide 2020-01-06 14:04:25 +01:00
Loïc Hoguin
db0d6f8d25
Use active,N
This reduces the number of times we need to ask for more packets,
and as a result we get a fairly large boost in performance,
especially with HTTP/1.1.

Unfortunately this makes Cowboy require at least Erlang/OTP 21.3+
because the ssl application did not have active,N. For simplicity
the version required will be Erlang/OTP 22+.

In addition this change improves hibernate handling in
cowboy_websocket. Hibernate will now work for HTTP/2 transport
as well, and stray or unrelated messages will no longer cancel
hibernate (the process will handle the message and go back into
hibernation).

Thanks go to Stressgrid for benchmarking an early version of this
commit: https://stressgrid.com/blog/cowboy_performance_part_2/
2020-01-06 12:58:14 +01:00
Loïc Hoguin
3a7232b019
No longer use erlang:get_stacktrace/0
It has been deprecated in OTP and the new way is available
on all supported OTP versions.
2019-12-31 15:10:38 +01:00
Loïc Hoguin
e81cd6328b
Add new RFCs to the list 2019-12-31 11:04:42 +01:00
Loïc Hoguin
525eeeecc9
Cowboy 2.7.0 2019-10-10 16:15:51 +02:00
Loïc Hoguin
a73004e966
Fix a number of low hanging todos 2019-10-10 16:04:28 +02:00
Loïc Hoguin
d52e84bdd9
Add shutdown_reason Websocket command
This allows changing the normal exit reason of Websocket
processes, providing a way to signal other processes of
why the exit occurred.
2019-10-10 11:33:35 +02:00
Loïc Hoguin
cc54c207e3
Implement flow control for HTTP/1.1
We now stop reading from the socket unless asked to,
when we reach the request body. The option
initial_stream_flow_size controls how much data
we read without being asked, as an optimization.
We may also have received additional data along
with the request headers.

This commit also reworks the timeout handling for HTTP/1.1
because the stray timeout message was easily reproducible
after implementing the flow control. The issue should be
gone for good this time.
2019-10-09 20:54:33 +02:00
Loïc Hoguin
0c4103984b
Add migration guide for Cowboy 2.7 2019-10-07 17:48:45 +02:00
Loïc Hoguin
b350180503
Add new stream handlers to the guide
Also link from the guide to manual pages.
2019-10-07 14:06:37 +02:00
Loïc Hoguin
80aef3cdaa
Document no date/server headers from response/headers commands 2019-10-07 13:45:07 +02:00
Loïc Hoguin
2e8fcb9a9e
Add cowboy_req:cast/2
Better than sending messages manually.
2019-10-07 13:25:49 +02:00
Loïc Hoguin
fad0ac8fb6
Document the set_options stream handler command 2019-10-07 12:07:23 +02:00
Loïc Hoguin
e25fb19bab
Document the log stream handler command 2019-10-07 11:58:45 +02:00
Loïc Hoguin
53bc54a860
Document the logger option 2019-10-07 11:43:44 +02:00
Loïc Hoguin
0342866c2e
Document cowboy_tracer_h 2019-10-07 10:43:22 +02:00
Loïc Hoguin
eaed063702
Document cowboy_metrics_h 2019-10-07 09:59:36 +02:00
Loïc Hoguin
3977f2b96f
Document the commands based Websocket interface
The old interface with ok|reply|stop tuples is deprecated.
2019-10-06 16:51:27 +02:00
Loïc Hoguin
2b38526351
Fix PUT when resource doesn't exist in flowchart
This required moving around a lot of things so hopefully I
did not add errors while doing so. Only time will tell.

Also add the 415 that can result from content_types_accepted.
2019-10-06 12:48:35 +02:00
Loïc Hoguin
62836cdddc
Document how to recover from cookie parsing errors 2019-10-06 10:18:16 +02:00
Loïc Hoguin
3e23aff1d1
Add Websocket option validate_utf8
This allows disabling the UTF-8 validation check
for text and close frames.
2019-10-05 17:32:50 +02:00
Loïc Hoguin
618c001291
Fix REST flowchart around 201 response for PUT
When the method is PUT we do not check the location header.
2019-10-05 11:39:53 +02:00
Loïc Hoguin
03dac1486d
Add cowboy_req:filter_cookies/2 2019-10-05 11:23:57 +02:00
Loïc Hoguin
28aee1f272
Document media type wildcard in content_types_accepted 2019-10-03 16:20:29 +02:00
Loïc Hoguin
99df823cc3
Document stopping the listener in App:stop/1 2019-10-03 10:09:35 +02:00
Loïc Hoguin
ab44985a9e
Fix HTTP/2 CVEs
A number of HTTP/2 CVEs were documented recently:

  https://www.kb.cert.org/vuls/id/605641/

This commit, along with a few changes and additions in Cowlib,
fix or improve protection against all of them.

For CVE-2019-9511, also known as Data Dribble, the new option
stream_window_data_threshold can be used to control how little
the DATA frames that Cowboy sends can get.

For CVE-2019-9516, also known as 0-Length Headers Leak, Cowboy
will now simply reject streams containing 0-length header names.

For CVE-2019-9517, also known as Internal Data Buffering, the
backpressure changes were already pretty good at preventing this
issue, but a new option max_connection_buffer_size was added for
even better control over how much memory we are willing to allocate.

For CVE-2019-9512, also known as Ping Flood; CVE-2019-9515, also
known as Settings Flood; CVE-2019-9518, also known as Empty Frame
Flooding; and similar undocumented scenarios, a frame rate limiting
mechanism was added. By default Cowboy will now allow 1000 frames
every 10 seconds. This can be configured via max_received_frame_rate.

For CVE-2019-9514, also known as Reset Flood, another rate limiting
mechanism was added and can be configured via max_reset_stream_rate.
By default Cowboy will do up to 10 stream resets every 10 seconds.

Finally, nothing was done for CVE-2019-9513, also known as Resource
Loop, because Cowboy does not currently implement the HTTP/2
priority mechanism (in parts because these issues were well known
from the start).

Tests were added for all cases except Internal Data Buffering,
which I'm not sure how to test, and Resource Loop, which is not
currently relevant.
2019-10-02 10:44:45 +02:00
Loïc Hoguin
cf84f59d9b
Add persistent_term support to the router 2019-09-28 15:40:41 +02:00
Loïc Hoguin
49af57d546
Implement backpressure on cowboy_req:stream_body
This should limit the amount of memory that Cowboy is using
when a handler is sending data much faster than the network.

The new max_stream_buffer_size is a soft limit and only has
an effect when the cowboy_stream_h handler is used.
2019-09-14 18:21:05 +02:00
Loïc Hoguin
42eb6bae69
Fix using custom fields in Req 2019-09-06 12:25:02 +02:00