Repository navigation
Remove sprintf-js path and backport Forge/Braces security fixes #13
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
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0969c9e
Replace vulnerable npm lockfile with pnpm
tsilva 78ba360
Patch transitive WebSocket dependency
tsilva e1a9c49
Patch newly disclosed brace expansion advisories
tsilva c418315
Patch fast URI parser advisories
tsilva 92bbeac
Eliminate remaining high-risk pnpm resolution paths
tsilva 755b28a
Run pnpm CI with the locked toolchain
tsilva 96927a9
Remove sprintf-js path and backport Forge and Braces security fixes
tsilva 5add904
Refresh existing security branch with current main fixes and action pins
tsilva 8573304
Preserve shared AST nodes while rejecting recursive cycles
tsilva 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| diff --git a/lib/check-depth.js b/lib/check-depth.js | ||
| new file mode 100644 | ||
| index 0000000000000000000000000000000000000000..0fbf12c49569e54a3bc1eeeedb193536fe16b2a5 | ||
| --- /dev/null | ||
| +++ b/lib/check-depth.js | ||
| @@ -0,0 +1,25 @@ | ||
| +'use strict'; | ||
| + | ||
| +// Validate before any recursive AST walk, including direct AST callers. | ||
| +module.exports = ast => { | ||
| + const pending = [[ast, 0]]; | ||
| + const active = new Set(); | ||
| + while (pending.length) { | ||
| + const [node, depth, leaving] = pending.pop(); | ||
| + if (leaving) { | ||
| + active.delete(node); | ||
| + continue; | ||
| + } | ||
| + if (!node || typeof node !== 'object') continue; | ||
| + if (depth >= 128 || active.has(node)) { | ||
| + const error = new SyntaxError('Brace AST exceeds the safe nesting limit or contains a cycle'); | ||
| + error.code = 'BRACES_MAX_DEPTH'; | ||
| + throw error; | ||
| + } | ||
| + active.add(node); | ||
| + pending.push([node, depth, true]); | ||
| + if (Array.isArray(node.nodes)) { | ||
| + for (const child of node.nodes) pending.push([child, depth + 1]); | ||
| + } | ||
| + } | ||
| +}; | ||
| diff --git a/lib/compile.js b/lib/compile.js | ||
| index dce69beb90ece5c3b0ca234a949418f9f34eedbc..ebf33f65092abeab15fed6011df4340515230eea 100644 | ||
| --- a/lib/compile.js | ||
| +++ b/lib/compile.js | ||
| @@ -1,9 +1,12 @@ | ||
| 'use strict'; | ||
|
|
||
| +const checkDepth = require('./check-depth'); | ||
| + | ||
| const fill = require('fill-range'); | ||
| const utils = require('./utils'); | ||
|
|
||
| const compile = (ast, options = {}) => { | ||
| + checkDepth(ast); | ||
| const walk = (node, parent = {}) => { | ||
| const invalidBlock = utils.isInvalidBrace(parent); | ||
| const invalidNode = node.invalid === true && options.escapeInvalid === true; | ||
| diff --git a/lib/expand.js b/lib/expand.js | ||
| index 35b2c41d6afdb8f0197959e26079f266e48370d3..4988f808dfac66cb4e28c52dae69ef87c102faae 100644 | ||
| --- a/lib/expand.js | ||
| +++ b/lib/expand.js | ||
| @@ -1,5 +1,7 @@ | ||
| 'use strict'; | ||
|
|
||
| +const checkDepth = require('./check-depth'); | ||
| + | ||
| const fill = require('fill-range'); | ||
| const stringify = require('./stringify'); | ||
| const utils = require('./utils'); | ||
| @@ -31,6 +33,7 @@ const append = (queue = '', stash = '', enclose = false) => { | ||
| }; | ||
|
|
||
| const expand = (ast, options = {}) => { | ||
| + checkDepth(ast); | ||
| const rangeLimit = options.rangeLimit === undefined ? 1000 : options.rangeLimit; | ||
|
|
||
| const walk = (node, parent = {}) => { | ||
| diff --git a/lib/parse.js b/lib/parse.js | ||
| index 3a6988e629f52aee6609dc5ec290a5e9ff47cecb..44b1591227e4ba698d9ae1b482c6ca707b75e325 100644 | ||
| --- a/lib/parse.js | ||
| +++ b/lib/parse.js | ||
| @@ -144,6 +144,11 @@ const parse = (input, options = {}) => { | ||
|
|
||
| if (value === CHAR_LEFT_PARENTHESES) { | ||
| block = push({ type: 'paren', nodes: [] }); | ||
| + if (stack.length >= 128) { | ||
| + const error = new SyntaxError('Brace pattern exceeds the safe nesting limit'); | ||
| + error.code = 'BRACES_MAX_DEPTH'; | ||
| + throw error; | ||
| + } | ||
| stack.push(block); | ||
| push({ type: 'text', value }); | ||
| continue; | ||
| @@ -210,6 +215,11 @@ const parse = (input, options = {}) => { | ||
| }; | ||
|
|
||
| block = push(brace); | ||
| + if (stack.length >= 128) { | ||
| + const error = new SyntaxError('Brace pattern exceeds the safe nesting limit'); | ||
| + error.code = 'BRACES_MAX_DEPTH'; | ||
| + throw error; | ||
| + } | ||
| stack.push(block); | ||
| push({ type: 'open', value }); | ||
| continue; | ||
| diff --git a/lib/stringify.js b/lib/stringify.js | ||
| index 8bcf872c31894f81a8c64d9202fd607e4fd7ea2b..706a62abe364d8c1f17dea8f736648c8251d227d 100644 | ||
| --- a/lib/stringify.js | ||
| +++ b/lib/stringify.js | ||
| @@ -1,8 +1,11 @@ | ||
| 'use strict'; | ||
|
|
||
| +const checkDepth = require('./check-depth'); | ||
| + | ||
| const utils = require('./utils'); | ||
|
|
||
| module.exports = (ast, options = {}) => { | ||
| + checkDepth(ast); | ||
| const stringify = (node, parent = {}) => { | ||
| const invalidBlock = options.escapeInvalid && utils.isInvalidBrace(parent); | ||
| const invalidNode = node.invalid === true && options.escapeInvalid === true; | ||
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,15 @@ | ||
| diff --git a/lib/rsa.js b/lib/rsa.js | ||
| index a4264822b4dcd6dca44ca3e59e410c982eed7183..94f5d3340818ad007e45c4c2578af52721f8f1f9 100644 | ||
| --- a/lib/rsa.js | ||
| +++ b/lib/rsa.js | ||
| @@ -1172,7 +1172,9 @@ pki.setRsaPublicKey = pki.rsa.setPublicKey = function(n, e) { | ||
| var capture = {}; | ||
| var errors = []; | ||
| if(!asn1.validate(obj, digestInfoValidator, capture, errors) || | ||
| - obj.value.length !== 2) { | ||
| + obj.value.length !== 2 || | ||
| + obj.value[0].value.length !== | ||
| + (('parameters' in capture) ? 2 : 1)) { | ||
| var error = new Error( | ||
| 'ASN.1 object does not contain a valid RSASSA-PKCS1-v1_5 ' + | ||
| 'DigestInfo value.'); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a caller uses the public AST overload with a cyclic
parentpointer, this validation passes because it traverses onlynodes, but the patched package'sexpand.jsstill followsblock.parentin an unboundedwhileloop. For example, a root containing aparennode whoseparentpoints to itself makesbraces.expand(root)hang indefinitely, so the new cyclic-AST protection and regression test do not cover every AST link that the walker follows; add cycle/depth protection to the parent-chain climbs as well.Useful? React with 👍 / 👎.