You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Contract on make-id-cookie should accept byte-strings #74
@soegaard reported on Slack that the contract on make-id-cookie currently requires the name and value arguments to be given as strings, so this program fails:
All other cookie-constructing functions permissively accept byte-strings for names and values (converting them with bytes->string/utf-8), and it seems like make-id-cookie should, too—I probably just missed it after I figured out RenaissanceBug/racket-cookies@c745ee5. I will try to make a PR soon.
In a5135d5, I believe @jeapostrophe should have changed -3 to -1 when he supplied #"" to base64-encode for the newline instead of the default #"\r\n".
A base64-encoded SHA-1 is always 28 bytes long, including exactly one = at the end for padding: since the length is fixed, we can drop the padding and return 27 bytes from mac. Right now, we are also dropping 2 significant digits of the SHA-1 hash.
I think this should be fixed and plan to include it in this patch. However, people's existing id cookies created with the current version of the library will not validate using a fixed version. I think the potential security implications outweigh the breakage, but I'm open to other opinions.
If it seems necessary, one option would be to add a function unverified-id-cookie?. I think it would be like valid-id-cookie?, but #:key would be optional and default to #f. If the key is #f, it would just check the name and timeout and not try to verify the digest. beyond checking that it syntactically could have been generated by some version of this library (i.e. it is 25 or 27 base64 digits). Alternatively, if you supply a key, it would check the digest but allow it to be two digits short.
That would let programmers make their own decisions about how to handle their existing id cookies. But, personally, I don't feel a need for such a function.
Activity
LiberalArtist commentedon Sep 15, 2019
While working on a patch, I believe I found another bug. In this code:
web-server/web-server-lib/web-server/http/id-cookie.rkt
Lines 83 to 87 in 245047b
In a5135d5, I believe @jeapostrophe should have changed
-3to-1when he supplied#""tobase64-encodefor the newline instead of the default#"\r\n".A base64-encoded SHA-1 is always 28 bytes long, including exactly one
=at the end for padding: since the length is fixed, we can drop the padding and return 27 bytes frommac. Right now, we are also dropping 2 significant digits of the SHA-1 hash.I think this should be fixed and plan to include it in this patch. However, people's existing id cookies created with the current version of the library will not validate using a fixed version. I think the potential security implications outweigh the breakage, but I'm open to other opinions.
LiberalArtist commentedon Sep 15, 2019
If it seems necessary, one option would be to add a function
unverified-id-cookie?. I think it would be likevalid-id-cookie?, but#:keywould be optional and default to#f. If the key is#f, it would just check the name and timeout and not try to verify the digest. beyond checking that it syntactically could have been generated by some version of this library (i.e. it is 25 or 27 base64 digits). Alternatively, if you supply a key, it would check the digest but allow it to be two digits short.That would let programmers make their own decisions about how to handle their existing id cookies. But, personally, I don't feel a need for such a function.
jeapostrophe commentedon Sep 16, 2019
You should just change the
-3to a-1. It was simply a mistake.web-server/http/id-cookie: accept string names & values; fix signatures
web-server/http/id-cookie: accept names & values as bytes; fix signat…
web-server/http/id-cookie: accept names & values as bytes; fix signat…
web-server/http/id-cookie: accept names & values as bytes; fix HMAC
web-server/http/id-cookie: accept names & values as bytes; fix HMAC
web-server/http/id-cookie: accept names & values as bytes; fix HMAC
web-server/http/id-cookie: accept names & values as bytes; fix HMAC