Skip to content

fix: audit 2026-11-10 CPU, hang, and robustness bugs - #6

Open
rush-skills wants to merge 20 commits into
masterfrom
cursor/audit-fixes-2026-11-10-afa9
Open

rush-skills wants to merge 20 commits into
masterfrom
cursor/audit-fixes-2026-11-10-afa9

Conversation

@rush-skills

Copy link
Copy Markdown
Member

Fixes from the 2026-11-10 whole-repo audit against origin/master 5ecd1e8. Behaviour for normal input is unchanged except where the old behaviour was a hang, a 500, a fail-open gate, or a CommonMark fence bug.

High (all done)

# Fix
1 Empty / whitespace-only add / addPhrases entries are rejected by validateConfig, filtered in detectors, and exec loops bump lastIndex on a zero-width match so the matcher cannot spin forever.
2 flexibleSource collapses whitespace runs to one flexible group, so a 4-space custom phrase against 5 000 blanks finishes in under 50 ms.
3 splitSentences abbreviation back-walk is capped at longest abbreviation + 1. 'a.'.repeat(50000) finishes in under 200 ms.
4 Shared makeLineIndex (line starts + binary search) replaces the five substring(0, i).split('\n') copies. Output is the same 1-based line/column, including CRLF.
5 fix_duplicates detects once and removes right-to-left. Text and fix-list order match the old loop; 8k duplicates finish in under 200 ms. No length cap added (needs your call — see below).

Medium (done)

# Fix
7 HTML comments scanned with indexOf; unclosed <!-- is O(n). '<!--'.repeat(25000) under 200 ms.
8 AI-tells overlap dedupe tracks maxKeptEnd instead of kept.some.
11 --max-warnings must be an integer ≥ -1 at parse time; otherwise Error: --max-warnings must be an integer and exit 2. action.yml unchanged beyond the summary-line grep in #20.
12 null / array / non-object /mcp bodies return JSON-RPC -32600 with id: null instead of a non-JSON-RPC 500. Version errors use id ?? null.

Other low-risk (done)

# Fix
10 Fence open length recorded; close only on same character with length ≥ opener. A ```js``` line is not a fence opener.
18 check_file stats first: require a regular file and size ≤ MAX_TEXT_LENGTH * 4 bytes, then the character check.
19 GitHub ::warning data/properties escaped (%, CR/LF, ,, :).
20 Action total-issues reads ^Found [0-9]+ issue (summary line), not the first Found N in annotations.
21 Direct zod dependency on wsc-mcp (^3.25 || ^4.0).
24 Unexpected MCP tool errors console.error('mcp tools/call failed', toolName, err) before -32603.
29 Stale version-sync asserts removed from unused scripts/test-all.sh.
31 validateConfig rejects extra keys on nominalization add items (matches schema.json).
32 markdown.ts and linecol.ts added to coverage include; regression tests with timing bounds for each perf fix.

Needs your decision — skipped (no new limits or policy changes)

These were called out as owner decisions. Nothing below is in this PR.

# Question Conservative default if you want it later
6 Should remote fix_duplicates enforce the same 100 000-char limit as check_text? Yes — same error message as check_text. Easy to add in handleFixDuplicates / the npm fix_duplicates tool.
14 Body cap before JSON parse? Caps on config arrays/entries? e.g. 512 KB Content-Length + streamed byte count; 1 000 entries of ≤ 200 chars in validateConfig.
15 Is the Worker on Free (10 ms CPU) or Paid? Drop MAX_TEXT_LENGTH from 100k? Only if Free: ~20–25k chars. Paid can keep 100k.
16 Move /api/* and /mcp no-store / nosniff / CORS into hooks.server.ts (and drop dead _headers blocks)? Yes for API/MCP including error responses; CSP on pages is a separate call.

Also skipped (behaviour or protocol change, or owned by PR #5):

  • 9 Duplicate detection across blank lines / masked code (changes results).
  • 13 wsc init overwrite vs --force.
  • 17 Restrict check_file to MCP roots / cwd.
  • 22 MCP 202 for notifications + ping.
  • 23 Tool errors as isError: true (response shape).
  • 28 npm ci --ignore-scripts / SHA-pin setup-node in the consumer Action.
  • 25, 26, 27, 30 owned by PR Automate releases with release-please #5 (workflows, smoke \|\| true, version strings). Left untouched.

No merge, deploy, npm publish, or GitHub/Cloudflare settings changes.

Local CI (this head)

Ran the jobs in .github/workflows/ci.yml locally:

Job Command Result
test / typecheck npm run check 0 errors, 0 warnings
test / tests npm test 541 passed (26 files)
test / build npm run build ok (adapter-cloudflare)
mcp-server / build cd mcp-server && npm run build tsc ok
mcp-server / smoke timeout 2 node mcp-server/dist/mcp-server/index.js < /dev/null || true same as CI (ignored)
cli / build cd cli && npm run build tsc ok
cli / smokes stdin check, clean --quiet, list, list weaselWords, init ok

Extra, not in CI: npm run test:coverage meets thresholds (stmts 96.52, branches 93.52, funcs 96.63, lines 98.30).

Perf regression tests (timing bounds) live in:

Open in Web Open in Cursor 

cursoragent and others added 20 commits November 11, 2026 10:25
Empty or whitespace-only strings in detector add/addPhrases lists compiled
to a zero-width regex alternative, so exec() never advanced lastIndex.
Validate them out, filter them in detectors, and bump lastIndex on any
remaining zero-width match.

Co-authored-by: Ankur Singh <hello@anks.in>
Each space used to become its own `(…\s)+` group, so a phrase with N
spaces against a long blank run backtracked polynomially. Trim and
replace each whitespace run with a single flexible group; matching
semantics for normal multi-word phrases stay the same.

Co-authored-by: Ankur Singh <hello@anks.in>
Walking back over every letter/dot run at each period was O(n^2) on
inputs like a.a.a.… Cap the walk at the longest abbreviation length + 1;
a longer run can never match an abbreviation, so results are unchanged.

Co-authored-by: Ankur Singh <hello@anks.in>
getLineCol re-split the text prefix for every issue (O(issues × n)).
Build line-start offsets once and binary-search; output is identical
to the old 1-based line/column, including CRLF.

Co-authored-by: Ankur Singh <hello@anks.in>
fix_duplicates re-detected after every single removal, so cost grew
with (duplicates × n). Detect once and strip from the right; earlier
indexes stay valid and the cleaned text plus fix list match the old loop.

Co-authored-by: Ankur Singh <hello@anks.in>
An unclosed `<!--` made `/<!--[\s\S]*?-->/g` walk to EOF at every opener.
Walk with indexOf and stop when no closer remains; single-line comments
still become sentinels and multi-line comments still space-blank.

Co-authored-by: Ankur Singh <hello@anks.in>
kept.some() was O(k^2). Sorted spans are covered exactly when they end
at or before the furthest kept end, so one running maximum is enough.

Co-authored-by: Ankur Singh <hello@anks.in>
…open

NaN from Number('zero') made exitCode treat the gate as unlimited.
Parse --max-warnings as an integer >= -1 up front; otherwise print
an error and exit 2 so a blocking CI check cannot silently pass.

Co-authored-by: Ankur Singh <hello@anks.in>
A JSON body of null crashed handleMcpRequest and returned a non-JSON-RPC
500. Reject null/array/non-objects with -32600 and id null, and use
id ?? null on the version error so unknown ids follow the spec.

Co-authored-by: Ankur Singh <hello@anks.in>
A line like ```js``` opened a fence and blanked the rest of the
document, and a shorter inner fence could close an outer one. Record
the opener length, close only on the same character with length >=
that, and ignore backtick fences whose info string contains a backtick.

Co-authored-by: Ankur Singh <hello@anks.in>
readFile on a directory, FIFO, or huge device could hang or OOM the
local MCP server. Require a regular file whose size is within
MAX_TEXT_LENGTH * 4 bytes, then keep the character-length check.

Co-authored-by: Ankur Singh <hello@anks.in>
Unescaped %, CR/LF, commas, and colons in ::warning annotations split
or mis-attribute messages. Apply toolkit escaping so match text and
file paths stay on one annotation line.

Co-authored-by: Ankur Singh <hello@anks.in>
grep -oE 'Found [0-9]+' took the first hit anywhere, including
annotation text like [insert Found 12 here]. Match the CLI summary
line instead.

Co-authored-by: Ankur Singh <hello@anks.in>
server.ts imports zod but only the MCP SDK listed it, so a future
SDK that stops hoisting it would break the install. Add the same
range the SDK already peer-depends on.

Co-authored-by: Ankur Singh <hello@anks.in>
The catch path swallowed runtime exceptions with no log line. Write
the tool name and error to console (no user text) so Workers
observability can surface it.

Co-authored-by: Ankur Singh <hello@anks.in>
The script still required wsc-mcp 2.0.0 and wsc-lint 1.0.0, which
have not matched the packages for several releases, and nothing
invokes it. Remove that section; CI already tests the real versions.

Co-authored-by: Ankur Singh <hello@anks.in>
static/schema.json forbids additional properties on {word, suggestion}
entries, but validateConfig accepted them. Mirror the schema so a
typo in a .wscrc.json add item fails closed.

Co-authored-by: Ankur Singh <hello@anks.in>
Coverage skipped the markdown masker and the new line-index helper,
which is where several of the CPU fixes live. Count them so the
regression tests stay in the measured set.

Co-authored-by: Ankur Singh <hello@anks.in>
svelte-check rejected Record<string, unknown> as JsonRpcRequest. The
plain-object check already rejected null/arrays; go through unknown
for the remaining field destructure.

Co-authored-by: Ankur Singh <hello@anks.in>
…ells

Calling list_word_lists and the byte-size cap, masking a tilde fence,
and disabling aiTells in the all-off analyzer case keep coverage
above the configured thresholds after markdown.ts joined the include set.

Co-authored-by: Ankur Singh <hello@anks.in>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
wsc 3c10203 Nov 11 2026, 10:33 AM

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.

2 participants