Commit 316953b
fix(slack): timing-safe socket-token comparison (port 9824d33 slice) (#126)
Port the Slack slice of upstream 9824d33 (PR #441 adapter-hardening
pass): the forwarded Socket Mode events receiver validates the
`x-slack-socket-token` bearer against `socket_forwarding_secret`.
Encode both operands to UTF-8 bytes before `hmac.compare_digest`,
mirroring upstream `timingSafeStringEqual`'s `Buffer.from(x, "utf8")`
comparison. This keeps the constant-time guarantee, returns False on
length mismatch (the secret length is fixed at config time, so not a
leak), and avoids the `TypeError` that `str` `compare_digest` raises on
non-ASCII tokens (which would have surfaced as a crash rather than a
clean 401). Per CLAUDE.md Port Rule: `==` for signatures -> hmac.compare_digest.
Tests: spy on `hmac.compare_digest` to prove the timing-safe path is
exercised with byte operands (load-bearing against a regression to
`==`), plus a non-ASCII token is rejected with 401 rather than crashing.
Existing valid/invalid/missing-secret cases retained.
1 of 4 slices of the 9824d33 security pass (gchat/github/linear slices
ship as separate PRs). Refs #98.
https://claude.ai/code/session_01FyMxQn2BEAzmwKS1GZczKj
Co-authored-by: Claude <noreply@anthropic.com>1 parent 59e57d2 commit 316953b
2 files changed
Lines changed: 86 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1235 | 1235 | | |
1236 | 1236 | | |
1237 | 1237 | | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
1238 | 1244 | | |
1239 | | - | |
| 1245 | + | |
1240 | 1246 | | |
1241 | 1247 | | |
1242 | 1248 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
343 | 343 | | |
344 | 344 | | |
345 | 345 | | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
346 | 425 | | |
347 | 426 | | |
348 | 427 | | |
| |||
0 commit comments