Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid ambiguous encoding for HMAC input #1521

Merged
merged 1 commit into from
Nov 12, 2024
Merged

Conversation

yawkat
Copy link
Contributor

@yawkat yawkat commented Oct 24, 2024

When computing a HMAC of multiple inputs, it is important that the input encoding is unambiguous in order to avoid potential vulnerabilities when an attacker controls some of the input fields.

The old encoding was sessionID + "!" + random. An attacker that has limited control over the sessionID (e.g. when the sessionID is actually a username) may forge a hmac for another user with sessionID = "alice" by setting their own sessionID = "alice!eve". The server would then generate message = "alice!eve!random" and token = hmac("alice!eve!random") + "." + random. From this token, the attacker can create a token hmac("alice!eve!random") + ".eve!" + random which is a valid CSRF token for sessionID = "alice".

In practice, this is unlikely to be a problem. The session ID usually has a fixed format and is not attacker-controlled. Additionally, the attacker must know the original session ID, and bypass the CSRF token equality check. Nonetheless, as a defense in depth measure, the hmac in the example should use an unambiguous encoding. This PR adds the length of the sessionID and randomValue before their respective value to ensure this.

@mackowski mackowski merged commit 4ac5a1d into OWASP:master Nov 12, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants