Skip to content

fix(cache): harden response cache files (#764) - #766

Open
Kewe63 wants to merge 1 commit into
nansen-ai:mainfrom
Kewe63:fix/response-cache-file-hardening
Open

Kewe63 wants to merge 1 commit into
nansen-ai:mainfrom
Kewe63:fix/response-cache-file-hardening

Conversation

@Kewe63

@Kewe63 Kewe63 commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Reject linked, hard-linked, and non-regular response-cache entries before reading.
  • Publish cache updates through private same-directory temporary files and atomic rename.
  • Enforce 0600 for new and rewritten cache entries on POSIX.
  • Preserve primary I/O errors and avoid deleting a newer cache entry during read-side cleanup races.
  • Add focused coverage for linked entries, permissions, atomic replacement, descriptor cleanup, and replacement races.

Fixes #764

Checklist

  • Tests pass (npm test)
  • src/schema.json updated if new commands or flags were added — not applicable; no command surface changes
  • README.md updated if new top-level commands or categories were added — not applicable; no command surface changes
  • Changeset added (.changeset/) — only required for user-facing changes (new commands, flags, bug fixes, breaking changes)

Verification

  • npx vitest run src/__tests__/api-cache.test.js — 14 passed
  • Impacted response-cache/API suites — 6 files, 395 passed
  • Production-boundary synthetic PoC — 8 passed, including under umask 077
  • npm run lint — passed
  • npm run pretest — passed
  • git diff --check — passed

A full-suite attempt was terminated by the local environment during concurrent Vitest execution. The only failures observed before termination were existing feedback fixture timeouts that reproduce unchanged on the base revision; the focused and impacted suites for this patch are green.

@nansen-pr-reviewer

Copy link
Copy Markdown

nansen-pr-reviewer summary

The change hardens cache reads against symlinks and non-regular files and makes cache writes atomic with restrictive file modes. The implementation is covered by focused tests and includes the required changeset; no clear correctness or security defect was identified.

Deterministic check: success — No issues found

Risk: 3/5 (Elevated)

✅ Auto-approved — Deterministic gates passed: severity thresholds met, recommendation "approve", risk level 3/5 within threshold 3.


Token usage: 32,283 input, 2,258 output, 5,299 cache read | Usage Guide

Cooldown: for the next 10 minutes (counting from when this review finished), new pushes to this PR will not trigger another review — the next push after the window expires will. Need a fresh review sooner? Comment @nansen-pr-reviewer[bot] re-review.

@nansen-pr-reviewer nansen-pr-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Auto-approved by Nansen review

Deterministic gates passed: severity thresholds met, recommendation "approve", risk level 3/5 within threshold 3.

  • The deterministic severity check passed: No issues found
  • Risk level 3/5 (Elevated)
  • The model recommended: approve

Approval was decided by deterministic gates, not by the model. The model's recommendation can block auto-approval but never cause it.

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.

Response cache follows linked entries and preserves permissive modes on rewrite

1 participant