fix: harden getSdkAuthorizationData against injection and parsing bugs#1459
Open
aritro2002 wants to merge 1 commit intomainfrom
Open
fix: harden getSdkAuthorizationData against injection and parsing bugs#1459aritro2002 wants to merge 1 commit intomainfrom
aritro2002 wants to merge 1 commit intomainfrom
Conversation
Contributor
🚫 Missing Linked IssueHi 👋 This pull request does not appear to be linked to any open issue yet. Linking your PR to an issue helps keep the project tidy and ensures the issue is closed automatically. ✔️ How to fix this
Once linked, this check will pass automatically on your next push or when you re-run the workflow. Thanks for helping maintainers! 🙌 |
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.
Type of Change
Description
Description
Hardened the
getSdkAuthorizationDatafunction inUtils.resagainst injection and XSS attacks. The function decodes a base64-encoded SDK authorization token and extracts key-value pairs (publishableKey,clientSecret,customerId,profileId) that flow into downstream consumers. Previously, no input validation was applied to these user-controlled values, and several parsing bugs existed.Vulnerabilities fixed:
Unhandled
atobexception --Window.atobthrowsDOMExceptionon invalid base64 input. Addedtry/catcharound the entire function body, returning an empty result (allNone) on failure.Value truncation on
=characters --String.split("=") -> Array.get(1)discarded everything after the first=, silently corrupting values containing=(e.g., base64 padding). Replaced withindexOf("=") + sliceToEndto capture the full value.False-positive key matching --
String.includes(keyName)used substring matching, so a key like"key"would match"publishable_key". Replaced withString.startsWith(keyName ++ "=")for exact prefix matching.No input validation -- Extracted values were passed directly to downstream code with no sanitization. Added per-field allowlist regex validation using anchored (
^...$) patterns:publishableKey:^pk_(prd|snd|dev)_[a-zA-Z0-9]+$clientSecret:^[A-Za-z0-9_-]+_secret_[A-Za-z0-9]+$customerId:^[a-zA-Z0-9_-]+$profileId:^[a-zA-Z0-9_-]+$Fields that fail validation are returned as
None, preventing malicious payloads from propagating.Design decisions:
<meta>tag as defense-in-depth but is NOT relied upon as the sole XSS mitigation.JSON.stringifywas evaluated and rejected as an XSS mitigation since it does not escape<,>,(,).Changes Summary
Modified Files:
src/Utilities/Utils.res--getSdkAuthorizationDatafunction (lines 1910-1956): addedtry/catchforatob, fixed value extraction, fixed key matching, added per-field regex validation.How did you test it?
Normal Flow:

Checklist
npm run re:build