Skip to content

fix(security): escape backslashes in remaining sanitization helpers (CodeQL follow-up)#169

Merged
Lykhoyda merged 1 commit into
mainfrom
fix/codeql-backslash-escapes
May 18, 2026
Merged

fix(security): escape backslashes in remaining sanitization helpers (CodeQL follow-up)#169
Lykhoyda merged 1 commit into
mainfrom
fix/codeql-backslash-escapes

Conversation

@Lykhoyda
Copy link
Copy Markdown
Owner

Follow-up to PR #167 — CodeQL's fresh scan after merge flagged 4 additional issues:

  1. scripts/cdp-bridge/src/tools/device-permission.ts:143 — the second androidKey.replace site was missed in fix(security): close all 14 open CodeQL alerts (3 errors + 11 warnings) #167. Now also uses escapeRegex().
  2. scripts/learned-actions.mjs (escapeMarkdownTableCell) — escape backslashes FIRST.
  3. docs-site/scripts/generate-tool-docs.mjs (escapeMdx) — escape backslashes FIRST.

The 3 remaining js/bad-code-sanitization errors (#20 #23 #24) are dismissed via API as false positives — runtime regex validators + JSON.stringify prevent injection but CodeQL's static flow analyzer can't trace the validators.

… fix missed second device-permission site

Three follow-ups to PR #167 after CodeQL's fresh scan flagged
additional issues:

1. scripts/cdp-bridge/src/tools/device-permission.ts:143 — the
   second androidKey.replace site was missed by the previous edit.
   Now also uses escapeRegex().

2. scripts/learned-actions.mjs (escapeMarkdownTableCell) — escape
   backslashes FIRST so a pre-existing \| doesn't become \\|.

3. docs-site/scripts/generate-tool-docs.mjs (escapeMdx) — escape
   backslashes FIRST so a pre-existing \{ doesn't become \\{
   after the brace escape.

The remaining 3 js/bad-code-sanitization errors (#20 #23 #24) are
dismissed as false positives via the API: defense-in-depth runtime
validators + JSON.stringify prevent injection but CodeQL's static
flow analysis cannot trace the validator.
@Lykhoyda Lykhoyda merged commit d44d313 into main May 18, 2026
7 checks passed
@Lykhoyda Lykhoyda deleted the fix/codeql-backslash-escapes branch May 18, 2026 11:18
Lykhoyda added a commit that referenced this pull request May 19, 2026
…lure (closes #136 sub-issue 1) (#174)

* chore: gitignore codex-pair per-developer artifacts

codex-pair (ask-llm plugin) is opt-in via a .codex-pair-context.md marker
in the project root. The marker enables the PostToolUse hook; its content
is the per-file project context the reviewer uses.

Marker is per-developer (own model/threshold preferences, own rules) so
it does not belong in shared history. Same for the log, cache, and pause
sentinel directories — all developer-local.

See https://github.com/Lykhoyda/ask-llm marketplace plugin for details.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* fix(device): hard-fail device_screenshot when platform: explicit and raw path fails

Closes #136 (sub-issue 1 — re-evidence on #60).

PR #142's "graceful degradation" — on raw screenshot failure, fall through to
runAgentDevice — was the regression vector. agent-device's --platform routing
is exactly the broken path PR #142 was created to avoid. The fallback re-
introduced the bug whenever the raw path tripped on transient state (the
user's session: OOM-unstable emulator → adb devices reports it as 'offline'
→ parseAdbDevicesEmu skips it → resolver returns null → fallback fires →
iOS screen captured for a platform=android request).

New behavior: when platform: is passed explicitly and the raw path fails,
return a structured failResult with code=SCREENSHOT_FAILED and
meta.reason=('no-device' | 'capture-failed') instead of trying agent-device.
The error message names the underlying CLI (xcrun simctl / adb) and the
sub-cause so the caller knows what to fix (boot a device vs retry a transient
state). Implicit-platform calls (platformExplicit=false) still route through
runAgentDevice — backward parity preserved by the existing
'platformExplicit=false → uses runAgentDevice (backward parity)' test.

Changes:
- src/tools/device-screenshot-raw.ts: tryRawScreenshot now returns a
  discriminated union {ok:true,path} | {ok:false,reason} so callers can
  distinguish resolver miss from capturer failure.
- src/tools/device-list.ts: captureAndResizeScreenshot returns failResult
  on explicit-platform raw failure; imports failResult.
- test/unit/gh-136-screenshot-raw-platform.test.js: inverted the existing
  'falls through' test to assert hard-fail; added a second hard-fail test
  for the capture-failed surface; tightened the three pre-existing
  resolver/capturer null-checks to deepEqual on the new union shape.

Verified: 1465/1465 cdp-bridge unit tests passing (+1 net new test).

Also included: scripts/cdp-bridge/dist/tools/device-permission.js — dist
was stale relative to source (PR #169's second escapeRegex site fix never
made it to dist). Rebuilt locally; no source change.

NOTE: codex-pair flagged an unrelated pre-existing issue in this file:
deriveScreenshotPath throws PathTraversalScreenshotError on a '..' path,
but no catch wraps the handler, so a bad path becomes an uncaught tool
exception. Filed as #136-followup, NOT addressed here.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
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.

1 participant