utils: isomorphic Smart CDN URL signing and signParams (WebCrypto) - #477
Merged
Conversation
…pto) Move the Smart CDN URL assembly (encoding, sorted query, auth_key/exp, sig=sha256:hex) into src/smartCdn.ts so the synchronous Node signer and a new async WebCrypto getSignedSmartCdnUrl on the root export share it and cannot drift. Uppy's @uppy/transloadit-storage and the Console each carry a browser reimplementation today; this lets them depend on the package instead. signParams/verifyWebhookSignature also accept sha512, matching signParamsSync. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
@transloadit/utilsroot export gains an async, WebCrypto-basedgetSignedSmartCdnUrlthat works in browsers (secure origins), edge runtimes and Node, producing byte-identical URLs to the synchronous signer in@transloadit/utils/node.auth_key/exp,sig=sha256:<hex>) moved tosrc/smartCdn.ts; both signers are thin wrappers over it, so they cannot drift apart.SmartCdnUrlOptionsis unchanged and still exported from./node.signParams/verifyWebhookSignatureacceptsha512in addition tosha1|sha256|sha384, matching whatsignParamsSyncalready allowed.crypto.subtleonhttps:///localhost).Why
Uppy's
@uppy/transloadit-storage(transloadit/uppy#6506) and the Console File Library (transloadit/content#5810) each carry their own browser reimplementation of Smart CDN URL signing today. With this they can depend on@transloadit/utilsinstead of maintaining a third copy.Verified
packages/utils/test/smartCdn.test.ts: hard-coded known-answer URL for both signers, HMAC-SHA256 of the documented string-to-sign, default one-hour expiry parity, validation parity, insecure-context error, andsignParamsvssignParamsSyncparity for all four algorithms.yarn verify(changesets, publish, deps, biome, tsc, transloadit-sync, all unit suites: utils 9, node 248, zod/types, notify-url-relay 22) andyarn knipclean.🤖 Generated with Claude Code