Repository navigation
fix(wp): remove sjcl fallback in eddsa mpcv2 and screen v1 cipher mode #10070
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
pranavjain97
merged 4 commits into
master
from
pranavjain/wcn-3831-remove-sjcl-fallback-in-eddsampcv2-and-screen-v1-cipher-mode
Nov 6, 2026
+164
−5
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
27b4481
fix(sdk-api): reject non-ccm mode before v1 SJCL decrypt
pranavjain97 622de58
fix(sdk-core): cap iter and mode in EdDSA v1 recovery decrypt
pranavjain97 c58ce64
fix(sdk-core): share v1 envelope screening with sdk-api
pranavjain97 154d18a
fix(sdk-core): screen the envelope SJCL actually decodes
pranavjain97 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import * as sjcl from '@bitgo/sjcl'; | ||
|
|
||
| /** | ||
| * Upper bound on PBKDF2 iterations accepted from a legacy v1 (SJCL) envelope. | ||
| * BitGo only ever wrote 10,000; this cap is 10x that. | ||
| */ | ||
| export const LEGACY_V1_MAX_ITER = 100_000; | ||
|
|
||
| /** | ||
| * Refuse hostile legacy v1 envelopes before SJCL sees them. SJCL reads `iter` and `mode` | ||
| * from the envelope and has no upper bound on the iteration count, so a tampered envelope | ||
| * could stall the caller with a huge PBKDF2 run or select the weak OCB2 mode. Absent | ||
| * `iter` and `mode` take SJCL's defaults. | ||
| * | ||
| * The check reads the envelope with SJCL's own decoder, not JSON.parse. SJCL strips all | ||
| * whitespace before decoding, so a key such as "it er" is `iter` to SJCL but unknown to | ||
| * JSON.parse. Input SJCL cannot decode is left for `sjcl.decrypt` to report. | ||
| * | ||
| * @param ciphertext serialized v1 envelope | ||
| * @throws if `iter` is not an integer between 1 and LEGACY_V1_MAX_ITER, or `mode` is not `ccm` | ||
| */ | ||
| export function assertSafeLegacyV1Envelope(ciphertext: string): void { | ||
| let envelope: { iter?: unknown; mode?: unknown }; | ||
| try { | ||
| envelope = sjcl.json.decode(ciphertext); | ||
| } catch { | ||
| return; | ||
| } | ||
| const { iter, mode } = envelope; | ||
| if ( | ||
| iter !== undefined && | ||
| !(Number.isInteger(iter) && (iter as number) >= 1 && (iter as number) <= LEGACY_V1_MAX_ITER) | ||
| ) { | ||
| throw new Error(`v1 envelope: iter out of range, expected an integer between 1 and ${LEGACY_V1_MAX_ITER}`); | ||
| } | ||
| if (mode !== undefined && mode !== 'ccm') { | ||
| throw new Error('v1 envelope: unsupported mode, expected ccm'); | ||
| } | ||
| } | ||
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.