Skip to content

fix(fresh): tolerate malformed form cookies - #2640

Merged
rickylabs merged 6 commits into
mainfrom
fix/fresh-malformed-csrf-cookie
Nov 17, 2026
Merged

rickylabs merged 6 commits into
mainfrom
fix/fresh-malformed-csrf-cookie

Conversation

@rickylabs

@rickylabs rickylabs commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Summary

Treat malformed Cookie headers as a missing form CSRF token. Protected POSTs return the existing rejection, csrf:false submissions proceed, and GET renders a fresh token.

Scope

  • Archetype / area: Archetype 4, packages/fresh

Closes #2632

Slices

  • S1 Plan and design checkpoint
  • S2 Reader correction and reader/POST/GET regressions
  • S3 Local gates, independent evaluation and documentation follow-up

Validation

  • Structured focused tests: before fix 10 failures; after fix 20/20 pass.
  • Independent full Fresh source tests: 315/315 pass.
  • Structured check/lint/fmt, quality:gate, release:preflight, docs:accuracy, docs:exports-drift and JSR audit pass.
  • Full-package doc lint: 47 pre-existing diagnostics, measured identically at base by the evaluator; form entrypoint zero.
  • Local scaffold runtime E2E N/A: no scaffold, Aspire helper or runtime wiring changes. CI runs its path-selected tiers after ready_for_review.
  • Required checks at head deb6b21cfcfc6b9d94e7291eb21def7072b4539b: quality PASS; deps-report SKIPPED by policy. Review-thread gate PASS (0 threads, 0 unanswered). Evidence: https://github.com/rickylabs/netscript/actions/runs/43919045089/job/133481486020

Harness

  • Run dir: .llm/runs/fix-fresh-malformed-csrf-cookie--issue-2632/
  • PLAN-EVAL: N/A — bounded parser correction with unchanged public contract.
  • IMPL-EVAL: PASS, independent reproduction and full package suite: fix(fresh): tolerate malformed form cookies #2640 (comment)
  • Runtime source unchanged since evaluation; follow-ups refresh reference prose and its shipped prose, export-surface and publish-asset carriers using canonical generators. Corpus checks pass.

Drift / Debt

  • Existing package doc-lint residue is proven unchanged. No new debt.
  • Decision: catch only SyntaxError from Cookie parsing; other failures propagate.

Definition of Done

  • All four issue acceptance cases independently verified and linked below.
  • Documentation describes malformed-cookie behavior.
  • Local scoped gates and independent evaluation complete, with baseline doc-lint limits recorded.
  • Branch, labels and milestone follow repository conventions.
  • No unrelated lock or source churn committed.
issue: 2632
entries:
  - box-index: 1
    evidence: "https://github.com/rickylabs/netscript/pull/2640#issuecomment-6922841910 — reader regression fails before fix, passes after"
  - box-index: 2
    evidence: "https://github.com/rickylabs/netscript/pull/2640#issuecomment-6922841910 — protected POST returns CSRF rejection"
  - box-index: 3
    evidence: "https://github.com/rickylabs/netscript/pull/2640#issuecomment-6922841910 — csrf:false POST invokes mutation and succeeds"
  - box-index: 4
    evidence: "https://github.com/rickylabs/netscript/pull/2640#issuecomment-6922841910 — GET renders and sets matching fresh token cookie"

🤖 Generated with Codex

@rickylabs rickylabs added this to the 0.0.10 milestone Nov 16, 2026
@rickylabs rickylabs added status:impl-eval and removed status:plan Harness plan phase labels Nov 16, 2026
@rickylabs

Copy link
Copy Markdown
Owner Author

[PHASE: IMPL]

Commit d0f5f0b treats Cookie parser SyntaxError as a missing CSRF token. Regression tests cover the reader, GET rendering/token renewal, CSRF rejection and csrf:false POST success for empty, =x and a=1;=x headers.

The structured focused test command failed with 10 Cookie parser exceptions before the reader change and passes 20/20 after it. Structured check/lint/fmt, quality:gate, release:preflight, docs:accuracy and JSR audit pass. Full-package doc lint has 47 diagnostics in unchanged surfaces; the form entrypoint has zero. Details: .llm/runs/fix-fresh-malformed-csrf-cookie--issue-2632/worklog.md.

Independent evaluation is next. No merge or publication is authorized.

@rickylabs

Copy link
Copy Markdown
Owner Author

[PHASE: IMPL-EVAL] [VERDICT: PASS]

Independent evaluation of head d0f5f0bae against issue #2632: the fix is minimal, the error handling is genuinely narrow, and all four acceptance criteria are satisfied and independently demonstrated.

Verdict basis

  • Acceptance — all four met. readCsrfToken returns undefined for an unparsable Cookie header; a POST with a malformed cookie receives the CSRF rejection result (a form result, not a Response); a csrf: false form accepts the POST with the mutation actually running; a GET renders, issues a fresh token and sets the matching cookie.
  • Regression quality is genuine. Reverting only the reader to its base implementation reproduces exactly 10 failures with SyntaxError: Cookie cannot start with '=' at all three call sites (reader unit, GET loader, POST handler); at head the same suite passes 20/20. The full packages/fresh/src suite passes 315/315.
  • Narrow handling confirmed. Only SyntaxError maps to undefined; an injected non-SyntaxError failure propagates unchanged. @std/http@1.1.4 getCookies has exactly one throw site (an empty cookie key), so the catch is precise today.
  • Verification is not weakened. Valid token → success; mismatched token → rejected; absent cookie → rejected. A malformed header fails closed: a valid CSRF cookie sitting next to a malformed segment is discarded, the POST is rejected and the mutation does not run.
  • Public surface unchanged. readCsrfToken(request: Request): string | undefined is byte-identical, the export map is untouched, and no any, unsafe cast or new lint-ignore was introduced.
  • Independent gate re-runs (all exit 0). Scoped check / lint / fmt (package-wide and slice-scoped), quality:gate (quality:scan + arch:check), release:preflight, docs:accuracy, docs:exports-drift, JSR audit for packages/fresh (dry-run OK), and agentic:pr-checks (40 checks, 0 current failures at head).
  • Doc-lint baseline is pre-existing. The full-package doc lint reports 47 diagnostics (exit 1). Measured on the base commit in a separate checkout, the result is identical — same totals (30 private-type refs + 17 missing JSDoc) and the same per-entrypoint distribution, with the changed form entrypoint at zero. None of the flagged files is in this diff, and the residue is already tracked as doctrine debt for the fresh route-documentation surface. This PR introduces no new diagnostic.
  • Process. PLAN-EVAL: N/A is recorded with a concrete reason before implementation; the ## Design checkpoint is present; the two commits match the planned slices; no speculative seams or new architecture debt.

Findings (non-blocking, for the parent)

  1. Low — stale public docs summary. The reference table for readCsrfToken still reads "Read the current CSRF token from a request cookie header" and omits the new malformed-cookie behavior. The signature is unchanged; only the descriptive sentence lags, and docs:exports-drift checks symbol coverage rather than JSDoc prose, so no gate catches it. Refresh that one line in this PR.
  2. Low — CI tier expectation. The plan records CLI E2E as not applicable on the grounds that no scaffold, Aspire helper or runtime wiring changed. That is true semantically, but the CI classifier is path-based: a packages/** code path schedules scaffold-static, scaffold-runtime-sqlite and scaffold-runtime once the PR leaves draft. Those tiers run in CI on ready_for_review; no local CLI E2E is required. Worth recording in the run artifacts so the merge-readiness step is not surprised.
  3. Info — merge-readiness bookkeeping. Before a status:ready-merge transition the PR body still needs a closing keyword, its five Definition-of-Done boxes checked, and a fenced acceptance-evidence block mapping the four issue [fresh] Form CSRF reader throws on a malformed Cookie header #2632 acceptance boxes to evidence. Issue [fresh] Form CSRF reader throws on a malformed Cookie header #2632's four acceptance boxes are now satisfied and still unchecked, so the close-gate would fail until they are ticked with linked evidence.

Next

  • Parent: apply finding 1, record finding 2 in the run artifacts, then complete finding 3 (closing keyword, DoD boxes, acceptance-evidence block, issue acceptance boxes) before the ready-for-review transition and the required head checks.
  • No merge, auto-merge, publication or readiness change is authorized by this verdict.

Full verdict and evidence: .llm/runs/fix-fresh-malformed-csrf-cookie--issue-2632/evaluate.md

@rickylabs
rickylabs marked this pull request as ready for review November 16, 2026 16:47
@rickylabs

Copy link
Copy Markdown
Owner Author

[PHASE: IMPL]

The required CI quality job found that the refreshed Fresh reference sentence also changes the shipped agent prose corpus. Regenerated it with the canonical tool on pinned Deno 2.9.7 and ran gen:assets-barrel. Decoded before/after comparison limits the content change to pages/reference/fresh/index.md and derived llms-full.txt; only the existing prose carrier changed. Corpus freshness now reports fresh=true, stalePaths=[], and release:preflight passes. No lock or implementation-source changes.

Independent code evaluation remains PASS; final checks will be verified at the new head.

@rickylabs

Copy link
Copy Markdown
Owner Author

[PHASE: IMPL]

Refreshed the MCP export-surface corpus after required CI identified its stale JSDoc snapshot. Canonical gen:mcp-export-corpus and check:mcp-export-corpus pass on pinned Deno 2.9.7. A row comparison proves exactly one changed surface, fresh ./form, with no added or removed surfaces. Source implementation and regression tests are unchanged since the independent PASS. Final head CI remains pending.

@rickylabs

Copy link
Copy Markdown
Owner Author

[PHASE: IMPL]

Completed the documentation generator dependency chain with gen:publish-assets and check:publish-assets. Runtime source and regression tests remain unchanged since independent IMPL-EVAL PASS. At head deb6b21, required quality is PASS and deps-report is SKIPPED by workflow policy; check:review-threads reports PASS, 0 threads and 0 unanswered. The PR is ready for review and remains unmerged, without status:ready-merge or auto-merge.

CI evidence: https://github.com/rickylabs/netscript/actions/runs/43919045089/job/133481486020

@rickylabs
rickylabs merged commit 84b2694 into main Nov 17, 2026
61 of 62 checks passed
@github-actions github-actions Bot added the canary:0.0.10-canary.4 Published NetScript prerelease 0.0.10-canary.4 label Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:fresh canary:0.0.10-canary.4 Published NetScript prerelease 0.0.10-canary.4 priority:p2 Medium status:shipped type:fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[fresh] Form CSRF reader throws on a malformed Cookie header

1 participant