fix: use hmac.compare_digest() for timing-safe HMAC comparison#16338
fix: use hmac.compare_digest() for timing-safe HMAC comparison#16338benthomasson wants to merge 1 commit intoansible:develfrom
Conversation
WebsocketSecretAuthHelper.verify_secret() compared HMAC digests using != which is vulnerable to timing attacks. Replace with hmac.compare_digest() for constant-time comparison. Fixes: AAP-68043 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughA single function in the WebSocket consumer replaces direct string equality checking with constant-time comparison using Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
|
@coderabbitai do existing unit tests cover this method, giving validation that regressions did not occur? |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 271 🏁 Script executed: Length of output: 9514 🏁 Script executed: Length of output: 3466
These tests flow through However, there are no direct unit tests that call In summary: the existing tests are sufficient to validate that the functional behavior hasn't regressed (valid secrets still work, invalid secrets are still rejected), but a dedicated unit test for |
|
What I need is a test that gives some input values where the keys match. And then the comparison finds they match. It's not at all obvious to me how the keys are produced in this indirect testing, and if the pivotal methods are not mocked. The coverage could be totally superficial. So what I'm looking for is a happy path test, which @pytest.mark.xfail(reason="Ran out of coding time.")
async def test_authorized(self, websocket_server_generator, application, admin):
server = websocket_server_generator('/websocket/')
"""
I ran out of time. Here is what I was thinking ...
Inject a valid session into the cookies in the header
server.scope['headers'] = (
(b'cookie', ...),
)
"""
connected, _ = await server.connect()
assert connected is True, "User should be allowed in via cookies auth via a session key in the cookies"Not okay with this. Nope no no. |
AlanCoding
left a comment
There was a problem hiding this comment.
Need some testing confirmation that this is regression-free and research on existing tests isn't doing it for me.




Summary
WebsocketSecretAuthHelper.verify_secret()compared HMAC digests using!=which is vulnerable to timing attackshmac.compare_digest()for constant-time comparisonhmacis already imported — this is a one-line fixFiles changed
awx/main/consumers.py!=→hmac.compare_digest()Fixes: AAP-68043
Test plan
Change Type
🤖 Generated with Claude Code
Summary by CodeRabbit