Skip to content

fix: resolve CodeQL code-scanning security alerts#140

Merged
laileni-aws merged 4 commits into
aws:mainfrom
laileni-aws:fix/codeql-code-scanning-alerts
Jul 15, 2026
Merged

fix: resolve CodeQL code-scanning security alerts#140
laileni-aws merged 4 commits into
aws:mainfrom
laileni-aws:fix/codeql-code-scanning-alerts

Conversation

@laileni-aws

Copy link
Copy Markdown
Contributor

Problem

There are 17 open CodeQL code-scanning alerts (separate from Dependabot):
ReDoS-prone regexes, incomplete sanitization, shell-command injection from
environment in dev scripts, an incomplete URL-substring check in a test, and a
workflow missing an explicit permissions block. None overlap with the
dependency PRs (#136 / #137 / #138), which only changed lockfiles.

Solution

Fix each alert at the source with minimal, behavior-preserving changes. Regex
rewrites were verified against the existing unit tests (indent(),
reformatStartUrl) plus ad-hoc equivalence checks.

Alert(s) Rule Location Fix
#19, #20, #21, #22 js/polynomial-redos textUtilities.ts indent() (\n+)(\n); block-comment regex → linear \/\*(?:[^*]|\*(?!\/))*\*\/; base64url /=+$/ → linear loop
#17, #18 js/polynomial-redos importAdderUtil.ts anchor use-strict regex (^); simplify require( detection
#15 js/polynomial-redos auth.ts trailing //# strip → linear loop
#16 js/polynomial-redos authUtil.ts trailing //# strip → linear loop
#7, #8 js/shell-command-injection-from-environment scripts/createRelease.ts execSync(string)execFileSync('git', [...]) (no shell)
#9 js/shell-command-injection-from-environment scripts/newChange.ts execSync(string)execFileSync('git', [...])
#12 js/incomplete-sanitization ssh.test.ts .replace('"','').replace(/"/g,'')
#1, #2, #3 js/incomplete-url-substring-sanitization referenceLogViewProvider.test.ts assert.ok(x.includes(url))assert.match(x, /.../)
#26 actions/missing-workflow-permissions .github/workflows/release.yml add top-level least-privilege permissions: contents: read
#10 js/disabling-certificate-validation proxyUtil.ts see note below

Note on #10 (proxyUtil.ts)

Disabling TLS verification here is an explicit, user opt-in that mirrors VS
Code's own http.proxyStrictSSL setting (used for corporate proxies with
self-signed certs). Removing it would drop a legitimate user feature, so the
behavior is kept — the log was upgraded to a warning and the intent
documented. If CodeQL still flags it, recommend dismissing as
"won't fix (by design)".

Verification

  • Regex rewrites validated in Node against the existing unit-test cases
    (indent() 5 cases, reformatStartUrl 6 cases) and base64url equivalence —
    all pass.
  • Full build/lint/tests: left to CI (draft).

Draft: opened as a draft for CI validation.


  • Treat all work as PUBLIC. Private feature/x branches will not be squash-merged at release time.
  • Your code changes must meet the guidelines in CONTRIBUTING.md.
  • License: I confirm that my contribution is made under the terms of the Apache 2.0 license.

laileni-aws and others added 3 commits July 14, 2026 17:35
Problem:
17 open CodeQL code-scanning alerts across source, tests, dev scripts,
and a workflow (ReDoS, incomplete sanitization, shell-command injection
from environment, and a missing workflow permissions block).

Solution:
- ReDoS (js/polynomial-redos): rewrite vulnerable regexes as linear
  equivalents - indent()/block-comment/base64url padding in
  textUtilities.ts; use-strict/require detection in importAdderUtil.ts;
  trailing '/' and '#' stripping in auth.ts and authUtil.ts (behavior
  verified against existing unit tests).
- Shell injection (js/shell-command-injection-from-environment): replace
  execSync(string) with execFileSync('git', [...args]) (no shell) in
  scripts/createRelease.ts and scripts/newChange.ts.
- Incomplete sanitization (js/incomplete-sanitization): replace all
  quotes, not just the first, in ssh.test.ts.
- URL substring checks (js/incomplete-url-substring-sanitization): use
  assert.match instead of includes() on URLs in
  referenceLogViewProvider.test.ts.
- Workflow permissions (actions/missing-workflow-permissions): add a
  least-privilege top-level 'contents: read' to release.yml (the publish
  job keeps its explicit 'contents: write').
- Certificate validation (js/disabling-certificate-validation): this is
  an explicit user opt-in mirroring VS Code's 'http.proxyStrictSSL';
  kept the behavior, upgraded the log to a warning, and documented it.

None of these overlap with the dependency PRs (aws#136-138).
The anchored /^\s*use\s+strict/ regex missed quoted directives like
'use strict'; (line starts with a quote), breaking
importAdderUtil 'first line after comments and use strict'. Allow an
optional leading quote: /^\s*['"]?use\s+strict/ (still anchored/linear).
@laileni-aws
laileni-aws marked this pull request as ready for review July 14, 2026 21:56
@laileni-aws
laileni-aws requested a review from a team as a code owner July 14, 2026 21:56
Comment thread packages/core/src/shared/utilities/textUtilities.ts Outdated
Add the global flag to the ReDoS-hardened block-comment regex so lines
with multiple block comments are fully stripped (and code between them is
preserved), matching the function's documented intent. Addresses review
feedback on aws#140; the g flag keeps the regex linear (no ReDoS).
@laileni-aws
laileni-aws enabled auto-merge (squash) July 15, 2026 00:02
@laileni-aws
laileni-aws merged commit c4226d9 into aws:main Jul 15, 2026
33 of 34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants