security: fix CodeQL code-scanning alerts and patch vulnerable dependencies#2788
Draft
laileni-aws wants to merge 3 commits into
Draft
security: fix CodeQL code-scanning alerts and patch vulnerable dependencies#2788laileni-aws wants to merge 3 commits into
laileni-aws wants to merge 3 commits into
Conversation
Adds a top-level least-privilege `permissions: contents: read` block to lsp-ci.yaml, npm-packaging.yaml and create-agent-standalone.yml. These workflows only check out code, build, run tests and upload build artifacts, so read-only access to repository contents is sufficient. Resolves CodeQL `actions/missing-workflow-permissions` alerts #1, #4, #5, #6, #7 and aws#8.
Fixes catastrophic-backtracking (ReDoS) regexes flagged by CodeQL js/redos. csharpDependencyGraph.ts: the namespace-matching sub-pattern used an unescaped `.` inside `([A-Z]\w*(.[A-Z]\w*)*)`, so `.` overlapped with `\w` and produced ambiguous, exponential backtracking. Escaping it to `\.` removes the ambiguity (linear time) and is also more correct, since C# namespace separators are literal dots. Applied to importRegex (alert aws#9), importNamespaceRegex (alert aws#10) and the identical searchRegEx in createNamespaceFilenameMapper (same root cause, not separately flagged). unitTestIntentDetection.ts: the Java signature pattern's annotation loop `(?:\s*@\w+(?:\(.*?\))?\s*)*` had leading AND trailing `\s*` inside a `*`-quantified group (whitespace-partition ambiguity) plus an unbounded `.*?` in the parentheses. Rewrote to `(?:\s*@\w+(?:\([^)]*\))?)*` (alerts aws#11, aws#12). Verified: attack strings from the CodeQL reports complete in <=1ms at 5000 repetitions (linear), and the existing unit tests for both files (56 cases) still pass.
Runs `npm audit fix` (non-breaking, lockfile-only) to update vulnerable transitive dependencies to patched versions within the ranges already allowed by their parents. No package.json changes; only package-lock.json. Reduces `npm audit` from 86 to 56 vulnerabilities (30 resolved): critical 11 -> 7, high 16 -> 4, moderate 51 -> 38, low 8 -> 7. Resolved advisories include axios, hono, protobufjs, node-forge, ws, undici, form-data, handlebars, fast-uri, follow-redirects, path-to-regexp, brace-expansion, picomatch, qs, postcss, http-proxy-middleware, websocket-driver, shell-quote and others. The remaining 56 require breaking major upgrades, have no upstream fix, or live inside version-pinned internal packages; see the PR description for the full breakdown and recommended follow-ups.
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.
Security: fix CodeQL code-scanning alerts and patch vulnerable dependencies
This PR addresses the open GitHub Advanced Security findings for
aws/language-servers:86 → 56
npm auditfindings (30 resolved), using a non-breaking,lockfile-only
npm audit fix. The remaining findings are documented below withthe reason each was not auto-fixed and a recommended follow-up.
All changes were verified with a full monorepo compile and the affected unit tests
(see Verification).
1. Code scanning (CodeQL) — 10 / 10 fixed
1a.
actions/missing-workflow-permissions(medium) — 6 alertsThree workflows did not set an explicit
permissionsblock, leaving theGITHUB_TOKENat the repository/organization default (often read-write). Theseworkflows only check out code, build, run tests, and upload build artifacts, so a
top-level least-privilege block was added:
.github/workflows/lsp-ci.yaml.github/workflows/npm-packaging.yaml.github/workflows/create-agent-standalone.ymlThis matches the existing convention already used in
release-please.yamlandcreate-agentic-github-prerelease.yml.1b.
js/redos— ReDoS (high) — 4 alertsTwo files contained regular expressions vulnerable to catastrophic backtracking.
server/.../securityScan/dependencyGraph/csharpDependencyGraph.ts(alerts #9, #10)The C# namespace sub-pattern
([A-Z]\w*(.[A-Z]\w*)*)used an unescaped..Because
.matches any character, it overlaps with the adjacent\w*, creating anambiguous nested quantifier that backtracks exponentially (e.g. on
using\tAaA0A0A0…). Escaping it to\.:Applied to
importRegex(#9),importNamespaceRegex(#10), and the identicalsearchRegExincreateNamespaceFilenameMapper(same root cause, not separatelyflagged — fixed proactively to avoid a future alert).
server/.../supplementalContextUtil/unitTestIntentDetection.ts(alerts #11, #12)The Java test-signature pattern's annotation loop
(?:\s*@\w+(?:\(.*?\))?\s*)*had both a leading and a trailing\s*inside a*-quantified group (a whitespace-partition ambiguity), plus an unbounded.*?inside the parentheses. Rewrote to:
which drops the ambiguous trailing
\s*(whitespace after an annotation is alreadyconsumed by the following token) and bounds the parenthesis content with
[^)]*.2. Dependabot — 30 advisories resolved (86 → 56)
Nearly all Dependabot alerts are transitive dependencies resolved in the single
root
package-lock.json. The safest, most reviewable remediation isnpm audit fixwithout--force: it updates transitive dependencies topatched versions within the semver ranges their parents already allow, editing
only the lockfile.
package.jsonis unchanged.npm auditbefore → after:Representative packages fully remediated (patched in-range):
axios,hono,protobufjs,node-forge,ws,undici,form-data,handlebars,fast-uri,fast-xml-builder,flatted,follow-redirects,path-to-regexp,brace-expansion,picomatch,qs,postcss,http-proxy-middleware,ip-address,launch-editor,websocket-driver,shell-quote,basic-ftp,@babel/core,@hono/node-server,@protobufjs/utf8,express,body-parser,express-rate-limit,@aws-sdk/xml-builder.3. What was NOT fixed here, and why
I deliberately avoided two tempting-but-risky approaches:
npm audit fix --force— would apply breaking major upgrades to directdependencies (build tooling, test frameworks), a high risk of breaking the build
and tests for moderate/low findings.
overrides+ full lockfile regeneration — I prototyped this. Itdoes resolve two more findings, but only by re-resolving the entire tree
(~8,500-line lockfile churn, unrelated version bumps, higher regression risk) for
little gain. A surgical override instead mis-resolved (npm deduped the SDK's
fast-xml-parser@4onto an API-incompatible5.x). For a security PR thatmaintainers must review, a tight, correct diff is worth far more than two extra
fixes obtained noisily. See Recommended follow-ups.
The remaining 56 findings group into the following root causes:
A. First-party / internal packages (fix upstream, not here)
@amzn/amazon-q-developer-streaming-client,@amzn/codewhisperer,@amzn/codewhisperer-runtime,@amzn/codewhisperer-streaming,@aws/lsp-core,@aws/lsp-partiql,@aws/language-server-runtimes. The advisories live insidethese published Amazon artifacts; they must be remediated by releasing new versions
of those packages, which this repo then consumes.
B. AWS SDK cluster pinned by internal packages
The
@amzn/*packages above pin@aws-sdk/core@3.731.0and its siblings atexact versions, freezing ~13
@aws-sdk/*packages at a pre-fix release(
3.529–3.893advisory range). They cannot be moved from this repo without a--force/override that would fight those exact pins. Fixing them properly meansbumping the internal
@amzn/*packages (A) or a coordinated@aws-sdkupgrade.C.
fast-xml-parser(critical) — partially mitigatedThe 5.x copy was patched to
5.10.1bynpm audit fix. The remaining criticalinstance is
4.4.1, pulled exclusively by the exact-pinned@aws-sdk/core@3.731.0from (B). It is fixable via anoverridespin but onlycleanly with a lockfile regen — see Recommended follow-ups.
D. Dev / build / test tooling needing breaking major upgrades
Not shipped in the runtime bundles; upgrading risks breaking builds/tests, so
deferred for a maintainer decision:
webpack-dev-server(→6) +sockjs,crypto-browserifypolyfill stack (browserify-sign,create-ecdh,elliptic),@wdio/mocha-framework+mocha,xmlbuilder2(→4, which pullsjs-yaml),sinon(→22),diff(→9),serialize-javascript(via wdio),esbuild,yaml-language-server(and itslodash/yaml).E. No upstream fix available
elliptic(no patched release),lodash(the advisory's "fixed"4.17.23is notpublished), and the
debug/spdx-licenses/bower-*chain below.F.
oss-attribution-generator(dev-only, unmaintained)This attribution tool drags in a vulnerable, unmaintained chain
(
bower-json,bower-license,npm-license,underscore,deep-extend,spdx-licenses, olddebug). It runs only at build time (license attribution) andships nothing at runtime. Recommend replacing it with a maintained alternative
(e.g.
license-checker, already a dependency, oross-attribution-builder).Recommended follow-ups
For maintainers who want to push further (each requires a
package-lock.jsonregeneration, i.e.
rm package-lock.json && npm install):Bigger items that should be owner-driven: bump the internal
@amzn/*packages (tocarry a patched
@aws-sdk), upgradewebpack-dev-serverto v6, and replaceoss-attribution-generator.Verification
npm run compile(full monorepo) — ✅ success, no type errors.csharpDependencyGraph.test.ts+unitTestIntentDetection.test.ts— ✅ 56 passing, 0 failing (covers every regex changed here).
repetitions against the patched regexes (linear), and valid-input correctness
(namespace/import extraction, Java test-intent true/false) is unchanged.
npm audit86 → 56;npm ciinstalls cleanly (0 invalid treeentries);
package.jsonuntouched.Commits
ci: restrict GITHUB_TOKEN permissions in CI workflows— §1a (6 alerts)fix: eliminate ReDoS in C# dependency-graph and Java test-intent regexes— §1b (4 alerts)fix: patch vulnerable transitive npm dependencies via npm audit fix— §2 (30 advisories)