<feed xmlns='http://www.w3.org/2005/Atom'>
<title>delta/ruby-gems/rack.git/lib/rack/multipart, branch main</title>
<subtitle>github.com: rack/rack.git
</subtitle>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/ruby-gems/rack.git/'/>
<entry>
<title>Fix comment about max Content-Disposition parameters</title>
<updated>2023-04-29T03:34:41+00:00</updated>
<author>
<name>Jeremy Evans</name>
<email>code@jeremyevans.net</email>
</author>
<published>2023-04-29T03:34:41+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/ruby-gems/rack.git/commit/?id=54990d39446caf046b5cbf19fd030204f850b480'/>
<id>54990d39446caf046b5cbf19fd030204f850b480</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Limit max size and number of parameters parsed for Content-Disposition</title>
<updated>2023-04-29T03:14:55+00:00</updated>
<author>
<name>Jeremy Evans</name>
<email>code@jeremyevans.net</email>
</author>
<published>2023-04-29T00:05:27+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/ruby-gems/rack.git/commit/?id=4f15681097997bd3f8b4f9ce1a7db296724e921a'/>
<id>4f15681097997bd3f8b4f9ce1a7db296724e921a</id>
<content type='text'>
Not strictly necessary, but this limits the damage in pathological
cases.  These limits are probably already too generous, we could
probably get by with 8 params and 1024 bytes.  One of tests uses
more than 1024 bytes, though.  Still, it seems unlikely any
legitimate requests would exceed these limits.  We could make the
limits configurable via an accessor method, if desired.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Not strictly necessary, but this limits the damage in pathological
cases.  These limits are probably already too generous, we could
probably get by with 8 params and 1024 bytes.  One of tests uses
more than 1024 bytes, though.  Still, it seems unlikely any
legitimate requests would exceed these limits.  We could make the
limits configurable via an accessor method, if desired.
</pre>
</div>
</content>
</entry>
<entry>
<title>Handle invalid Content-Disposition filename encodings</title>
<updated>2023-04-28T23:53:00+00:00</updated>
<author>
<name>Jeremy Evans</name>
<email>code@jeremyevans.net</email>
</author>
<published>2023-04-28T22:22:31+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/ruby-gems/rack.git/commit/?id=a54b61511e1d08919ae2c6392fa3084290f70dd8'/>
<id>a54b61511e1d08919ae2c6392fa3084290f70dd8</id>
<content type='text'>
Use BINARY for this, as we do for multipart encodings.  Extract a
find_encoding method for this.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Use BINARY for this, as we do for multipart encodings.  Extract a
find_encoding method for this.
</pre>
</div>
</content>
</entry>
<entry>
<title>Add Content-Disposition parameter parser</title>
<updated>2023-04-28T22:10:10+00:00</updated>
<author>
<name>Jeremy Evans</name>
<email>code@jeremyevans.net</email>
</author>
<published>2023-04-28T20:29:49+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/ruby-gems/rack.git/commit/?id=51b0c26bedf3b876188ff11d011d5c84e4941c49'/>
<id>51b0c26bedf3b876188ff11d011d5c84e4941c49</id>
<content type='text'>
The ReDoS fix in ee25ab9a7ee981d7578f559701085b0cf39bde77 breaks valid
requests, because colons are valid inside parameter values.  You cannot
use a regexp scan and ensure correct behavior, since values inside
parameters can be escaped.  Issues like this are the reason for the
famous "now they have two problems" quote regarding regexps.

Add a basic parser for parameters in Content-Disposition.  This parser
is based purely on String#{index,slice!,[],==}, usually with string
arguments for #index (though one case uses a simple regexp).  There
are two loops (one nested in the other), but the use of slice! ensures
that forward progress is always made on each loop iteration.

In addition to fixing the bug introduced by the security fix, this
removes multiple separate passes over the mime head, one pass to get
the parameter name for Content-Disposition, and a separate pass to get
the filename. It removes the get_filename method, though some of the
code is kept in a smaller normalize_filename method.

This removes 18 separate regexp contents that were previously used
just for the separate parse to find the filename for the content
disposition.

Fixes #2076
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The ReDoS fix in ee25ab9a7ee981d7578f559701085b0cf39bde77 breaks valid
requests, because colons are valid inside parameter values.  You cannot
use a regexp scan and ensure correct behavior, since values inside
parameters can be escaped.  Issues like this are the reason for the
famous "now they have two problems" quote regarding regexps.

Add a basic parser for parameters in Content-Disposition.  This parser
is based purely on String#{index,slice!,[],==}, usually with string
arguments for #index (though one case uses a simple regexp).  There
are two loops (one nested in the other), but the use of slice! ensures
that forward progress is always made on each loop iteration.

In addition to fixing the bug introduced by the security fix, this
removes multiple separate passes over the mime head, one pass to get
the parameter name for Content-Disposition, and a separate pass to get
the filename. It removes the get_filename method, though some of the
code is kept in a smaller normalize_filename method.

This removes 18 separate regexp contents that were previously used
just for the separate parse to find the filename for the content
disposition.

Fixes #2076
</pre>
</div>
</content>
</entry>
<entry>
<title>Limit file extension length of multipart tempfiles (#2069)</title>
<updated>2023-04-25T01:41:12+00:00</updated>
<author>
<name>Patrik Ragnarsson</name>
<email>patrik@starkast.net</email>
</author>
<published>2023-04-25T01:41:12+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/ruby-gems/rack.git/commit/?id=ccd445d7de85c4d5771e860add87104258b16f01'/>
<id>ccd445d7de85c4d5771e860add87104258b16f01</id>
<content type='text'>
- Fixes #1968 </content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
- Fixes #1968 </pre>
</div>
</content>
</entry>
<entry>
<title>Avoid rebuilding regex (#2042)</title>
<updated>2023-03-13T06:11:30+00:00</updated>
<author>
<name>John Hawthorn</name>
<email>john@hawthorn.email</email>
</author>
<published>2023-03-13T06:11:30+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/ruby-gems/rack.git/commit/?id=0b45107cb717c6e1c13f01f908f5c7f2b095fe57'/>
<id>0b45107cb717c6e1c13f01f908f5c7f2b095fe57</id>
<content type='text'>
Previously we would rebuild this regex once per-part. We can instead
compile it once per-request.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Previously we would rebuild this regex once per-part. We can instead
compile it once per-request.</pre>
</div>
</content>
</entry>
<entry>
<title>Limit all multipart parts, not just files</title>
<updated>2023-03-02T23:00:33+00:00</updated>
<author>
<name>John Hawthorn</name>
<email>john@hawthorn.email</email>
</author>
<published>2022-12-08T23:54:28+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/ruby-gems/rack.git/commit/?id=8e8869d625e73e16b576b6d31b50208e9ec8002f'/>
<id>8e8869d625e73e16b576b6d31b50208e9ec8002f</id>
<content type='text'>
Previously we would limit the number of multipart parts which were
files, but not other parts. In some cases this could cause parsing of
maliciously crafted inputs to take longer than expected.

[CVE-2023-27530]
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Previously we would limit the number of multipart parts which were
files, but not other parts. In some cases this could cause parsing of
maliciously crafted inputs to take longer than expected.

[CVE-2023-27530]
</pre>
</div>
</content>
</entry>
<entry>
<title>Add general `Rack::BadRequest`. (#2019)</title>
<updated>2023-01-20T00:56:56+00:00</updated>
<author>
<name>Samuel Williams</name>
<email>samuel.williams@oriontransfer.co.nz</email>
</author>
<published>2023-01-20T00:56:56+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/ruby-gems/rack.git/commit/?id=723b5384f2dcd6541477a42262f75e45276b595c'/>
<id>723b5384f2dcd6541477a42262f75e45276b595c</id>
<content type='text'>
Used to communicate a class of exceptions that represent 400 Bad Request
semantics.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Used to communicate a class of exceptions that represent 400 Bad Request
semantics.</pre>
</div>
</content>
</entry>
<entry>
<title>Make RFC2183 work with Ruby 3.2's caching Regexp (#2014)</title>
<updated>2023-01-18T00:33:47+00:00</updated>
<author>
<name>John Hawthorn</name>
<email>john@hawthorn.email</email>
</author>
<published>2023-01-18T00:33:47+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/ruby-gems/rack.git/commit/?id=ffff364d8154af8d0abeafce9ebe4b5c4eade11c'/>
<id>ffff364d8154af8d0abeafce9ebe4b5c4eade11c</id>
<content type='text'>
Ruby 3.2 includes a cache-based regexp optimization, which is detailed
in https://bugs.ruby-lang.org/issues/19104. Which can speed up the regex
engine on many cases which would previously have resulted in a ReDoS.

One caveat of the implmentation is (quoting the issue):
&gt; A bounded or fixed times repetition nesting in another repetition
&gt; (e.g. /(a{2,3})*/). It is an implementation issue entirely, but we
&gt; believe it is hard to support this case correctly.

Because of that limitation the RFC2183 regex was not previously able to
use that optimization and was not able to mitigate two recent ReDoS
CVEs.

This commit manually expands a `{2}` fixed repetition, which allows Ruby
3.2's optimization to take effect.

Before:

    &gt; Regexp.linear_time?(/([0-9]{2})*/)
    =&gt; false
    &gt; Regexp.linear_time?(Rack::Multipart::RFC2183)
    =&gt; false

After:

    &gt; Regexp.linear_time?(/([0-9][0-9])*/)
    =&gt; true
    &gt; Regexp.linear_time?(Rack::Multipart::RFC2183)
    =&gt; true

I want to make this change as additional hardening against possible
ReDoS attacks in this regex. At the moment I don't know of any which
are unpatched.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Ruby 3.2 includes a cache-based regexp optimization, which is detailed
in https://bugs.ruby-lang.org/issues/19104. Which can speed up the regex
engine on many cases which would previously have resulted in a ReDoS.

One caveat of the implmentation is (quoting the issue):
&gt; A bounded or fixed times repetition nesting in another repetition
&gt; (e.g. /(a{2,3})*/). It is an implementation issue entirely, but we
&gt; believe it is hard to support this case correctly.

Because of that limitation the RFC2183 regex was not previously able to
use that optimization and was not able to mitigate two recent ReDoS
CVEs.

This commit manually expands a `{2}` fixed repetition, which allows Ruby
3.2's optimization to take effect.

Before:

    &gt; Regexp.linear_time?(/([0-9]{2})*/)
    =&gt; false
    &gt; Regexp.linear_time?(Rack::Multipart::RFC2183)
    =&gt; false

After:

    &gt; Regexp.linear_time?(/([0-9][0-9])*/)
    =&gt; true
    &gt; Regexp.linear_time?(Rack::Multipart::RFC2183)
    =&gt; true

I want to make this change as additional hardening against possible
ReDoS attacks in this regex. At the moment I don't know of any which
are unpatched.</pre>
</div>
</content>
</entry>
<entry>
<title>Fix ReDoS vulnerability in multipart parser</title>
<updated>2023-01-17T20:29:28+00:00</updated>
<author>
<name>Aaron Patterson</name>
<email>tenderlove@ruby-lang.org</email>
</author>
<published>2023-01-17T20:14:29+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/ruby-gems/rack.git/commit/?id=b79bb5ac6e7478aa02f624bd9ef00b25c2502af5'/>
<id>b79bb5ac6e7478aa02f624bd9ef00b25c2502af5</id>
<content type='text'>
This commit fixes a ReDoS vulnerability when parsing the
Content-Disposition field in multipart attachments

Thanks to @ooooooo_q for the patch!

[CVE-2022-44571]
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This commit fixes a ReDoS vulnerability when parsing the
Content-Disposition field in multipart attachments

Thanks to @ooooooo_q for the patch!

[CVE-2022-44571]
</pre>
</div>
</content>
</entry>
</feed>
