File tree Expand file tree Collapse file tree
ruby/ql/src/experimental/decompression-api Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <!DOCTYPE qhelp PUBLIC
2+ "-//Semmle//qhelp//EN"
3+ "qhelp.dtd">
4+ <qhelp >
5+ <overview >
6+ <p >
7+ Decompression of user-controlled data without taking proper precaution can
8+ result in uncontrolled and massive decompression on the server, resulting
9+ in a denial of service.
10+ </p >
11+ </overview >
12+ <recommendation >
13+ <p >
14+ When decompressing files supplied by the user, make sure that you're checking
15+ the size of the incoming data chunks before writing to an output.
16+ </p >
17+ </recommendation >
18+ <example >
19+ <p >
20+ In this example, the size of the input buffer chunks and total size are checked before each chunk is written to the output.
21+ </p >
22+ <sample src =" examples/decompress.rb" />
23+ </example >
24+
25+ <references >
26+ <a href =" https://cwe.mitre.org/data/definitions/409.html" >https://cwe.mitre.org/data/definitions/409.html</a >
27+ </references >
28+ </qhelp >
Original file line number Diff line number Diff line change 1+ class UsersController < ActionController ::Base
2+ def example_zlib_inflate
3+ MAX_ALLOWED_CHUNK_SIZE = 256
4+ MAX_ALLOWED_TOTAL_SIZE = 1024
5+
6+ user_data = params [ :data ]
7+ output = [ ]
8+ outsize = 0
9+
10+ Zlib ::Inflate . inflate ( user_data ) { |chunk |
11+ outsize += chunk . size
12+ if chunk . size < MAX_ALLOWED_CHUNK_SIZE && outsize < MAX_ALLOWED_TOTAL_SIZE
13+ output << chunk
14+ end
15+ }
16+ end
17+ end
You can’t perform that action at this time.
0 commit comments