Questions about the CSRF protection implementation #504
Unanswered
bbaterdene-gh
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
In this csrf.ts file the
secret
option is described as:However, in the
sign
function:If the secret is not defined, it returns the token directly — which seems fine.
But if the secret is defined, it hashes the token with SHA-256. It doesn't use the secret. Shouldn’t it use HMAC-SHA256 with the secret to ensure authenticity?
Hashing the token with SHA-256 guarentee integrity but not authenticity.
Also, in verifySignature:
If the secret is not defined, it just returns
true
. So doesn’t that mean the signature is effectively ignored?Additionally, it compares signatures using
===
. Isn’t this vulnerable to timing attacks?And the CSRF token isn’t masked — doesn’t that make it vulnerable to BREACH attacks?
Could you clarify the reasoning here? Are these intentional design choices or potential oversights?
Reference:
https://github.com/rails/rails/blob/main/actionpack/lib/action_controller/metal/request_forgery_protection.rb
Beta Was this translation helpful? Give feedback.
All reactions