Skip to content

Commit 522fdb7

Browse files
committed
fixup! fix(common): use cryptographically secure SHA-256 for transfer cache key generation
1 parent d9dfdb0 commit 522fdb7

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

packages/common/http/src/transfer_cache.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -552,9 +552,15 @@ let textEncoder: TextEncoder | undefined;
552552
/**
553553
* Generates a SHA-256 hash representation of a string.
554554
*
555-
* Note: A custom synchronous SHA-256 implementation is used here because the
556-
* Web Crypto API (`crypto.subtle.digest`) is strictly asynchronous (Promise-based),
557-
* whereas the transfer cache state lookup and interceptor flow must operate synchronously due to the HttpResource API.
555+
* Note: A custom synchronous SHA-256 implementation is used here because the Web Crypto API
556+
* (`crypto.subtle.digest`) is strictly asynchronous (Promise-based), whereas the transfer cache
557+
* state lookup and interceptor flow must operate synchronously due to the HttpResource API.
558+
*
559+
* The previous DJB2 hashing logic was vulnerable to pre-image and second-preimage attacks due to
560+
* its small 64-bit keyspace and mathematical simplicity. An attacker could craft colliding request
561+
* inputs to poison the cache, potentially causing a CDN or the application to serve the wrong
562+
* cached response to legitimate users. SHA-256 provides strong cryptographic collision resistance,
563+
* preventing cache key collision attacks.
558564
*/
559565
export function generateHash(value: string): string {
560566
textEncoder ??= new TextEncoder();

0 commit comments

Comments
 (0)