Skip to content

feat(tools): browser-export redaction + bounded oversized-read preview - #50042

Draft
arminanton wants to merge 1 commit into
NousResearch:mainfrom
arminanton:feat/file-tools-read-guards
Draft

feat(tools): browser-export redaction + bounded oversized-read preview#50042
arminanton wants to merge 1 commit into
NousResearch:mainfrom
arminanton:feat/file-tools-read-guards

Conversation

@arminanton

Copy link
Copy Markdown
Contributor

Hardens read_file: (1) browser-storage exports (cookie/localStorage/IndexedDB/conversation DBs etc., matched by _BROWSER_EXPORT_NAME_RE) are redacted on read to avoid leaking captured secrets into context; (2) oversized reads return a bounded _OVERSIZED_READ_PREVIEW_CHARS preview instead of erroring. tools/file_tools.py + 2 tests. Draft for review.

@alt-glitch alt-glitch added type/security Security vulnerability or hardening comp/tools Tool registry, model_tools, toolsets tool/file File tools (read, write, patch, search) P3 Low — cosmetic, nice to have labels Jun 21, 2026

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for targeting a real file-read redaction gap. The browser-export portion is still distinct from the related CDP guard in #54198, but this draft needs a current-main salvage rather than a direct application.

Problems

  • tools/file_tools.py:1010 sets a 1,000-character minimum preview. With file_read_max_chars=50 (covered by this PR's test), the result exceeds the configured cap; the test does not assert len(result["content"]).
  • tools/file_tools.py:117 uses generic redaction rather than file_read=True. Current main's file-content contract intentionally emits non-reusable sentinels for prefix credentials (agent/redact.py:544-547; tests/agent/test_redact.py:936-973).
  • Current main already supersedes the oversized-read change: tools/file_tools.py:1253-1280 and 1379-1414 provide line-boundary truncation plus next_offset in both read paths via 25f0cecf5e21bfe87aa27ffe8a8cb8734af2b1ca.

Suggested changes

  • Keep current truncation/continuation behavior and reapply only browser-export redaction on top of it.
  • Preserve the file_read=True non-reusable-sentinel guarantee and add cap-boundary coverage.

Automated hermes-sweeper review.

Comment thread tools/file_tools.py Outdated
total_lines = result_dict.get("total_lines", "unknown")
return json.dumps({
"error": (
preview_chars = max(1_000, min(max_chars - 1_000, _OVERSIZED_READ_PREVIEW_CHARS))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This minimum defeats small configured limits: with file_read_max_chars=50, this evaluates to 1,000, and the appended marker makes the returned content larger still. Bound the complete returned content to max_chars and add an assertion for the existing 50-character configuration test.

Comment thread tools/file_tools.py Outdated
if not content:
return content
if _looks_like_sensitive_browser_export(path):
content = redact_sensitive_text(content, force=True, code_file=False)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please preserve the current file-content redaction contract when salvaging this: file_read=True emits non-reusable sentinels for recognized prefixes, whereas this generic call retains a head/tail mask. Keep the browser-specific opaque-value pass, but do not regress that file-read guarantee.

@teknium1 teknium1 added sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-broad Sweeper blast radius: broad — a core path most sessions hit labels Jul 14, 2026
@arminanton
arminanton force-pushed the feat/file-tools-read-guards branch from a54e706 to 6f60b75 Compare August 22, 2026 21:39
@arminanton

Copy link
Copy Markdown
Contributor Author

Rebased onto current main and addressed both points.

Preview honors the configured cap (sweeper): the 1,000-character preview floor no longer exceeds file_read_max_chars. The read path uses main's _truncate_to_char_budget, which clamps content to the cap, and the tests now assert len(result["content"]) <= cap in two places (the 50-char config case and an explicit 1000-char case).

file_read=True redaction (sweeper): _redact_read_content now calls redact_sensitive_text(..., file_read=True) on both branches, preserving main's non-reusable-sentinel contract for file reads. Two new tests assert a prefix credential never leaks a reusable mask, for both browser-export and ordinary files.

Kept scoped to file-read/browser-export redaction (no overlap with the CDP guard in #54198). tests/tools/test_file_tools.py + test_file_read_guards.py → 88 passed.

read_file now scrubs browser cookie/localStorage/sessionStorage/IndexedDB
export dumps via _BROWSER_EXPORT_NAME_RE: an extra opaque-value pass masks
JSON "value" fields and the Netscape TSV cookie column that the built-in
code-file patterns intentionally skip. Redaction uses file_read=True so
prefix credentials become the non-reusable sentinel, preserving main's
file-content contract. The oversized-read change from the original draft is
dropped: current main already provides line-boundary truncation with
next_offset via _truncate_to_char_budget.
@arminanton
arminanton force-pushed the feat/file-tools-read-guards branch from 6f60b75 to 2991a3f Compare August 23, 2026 00:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/tools Tool registry, model_tools, toolsets P3 Low — cosmetic, nice to have sweeper:blast-broad Sweeper blast radius: broad — a core path most sessions hit sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data tool/file File tools (read, write, patch, search) type/security Security vulnerability or hardening

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants