Skip to content

Commit

Permalink
attack of the base64 regular expression
Browse files Browse the repository at this point in the history
  • Loading branch information
stopdropandrew committed Sep 11, 2008
1 parent 910e363 commit d31fec2
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/parkplace/s3.rb
Expand Up @@ -119,8 +119,17 @@ def put(bucket_name, oid)

raise IncompleteBody if @env.HTTP_CONTENT_LENGTH.to_i != readlen
if @env.HTTP_CONTENT_MD5
raise InvalidDigest unless @env.HTTP_CONTENT_MD5 =~ /^(?:[0-9a-zA-Z+\/]{4})*={0,2}$/
raise BadDigest unless fileinfo.md5 == @env.HTTP_CONTENT_MD5
b64cs = /[0-9a-zA-Z+\/]/
re = /
^
(?:#{b64cs}{4})* # any four legal chars
(?:#{b64cs}{2} # right-padded by up to two =s
(?:#{b64cs}|=){2})?
$
/ox

raise InvalidDigest unless @env.HTTP_CONTENT_MD5 =~ re
raise BadDigest unless fileinfo.md5 == @env.HTTP_CONTENT_MD5
end

fileinfo.path = File.join(bucket_name, File.basename(temp_path))
Expand Down

0 comments on commit d31fec2

Please sign in to comment.