Skip to content

fix(core): bound CSV preview before wide-row padding - #1927

Merged
phernandez merged 10 commits into
mainfrom
codex/security-csv-preview-budget
Oct 28, 2026
Merged

phernandez merged 10 commits into
mainfrom
codex/security-csv-preview-budget

Conversation

@phernandez

Copy link
Copy Markdown
Member

Why

A CSV header controls the width used to pad every retained row. The existing output limit is checked only after building the expanded table. A 5 KiB source with 5,000 columns and 200 short rows allocates over 9 MiB before rejection. Fixes #1912.

What Changed

Pass the configured output budget into preview rendering and count the exact projected UTF-8 Markdown size before table padding and rendering. Reuse the existing configured limit and error type.

Implementation Details

The projection includes header/separator widths, padded cells, escaped pipes/backslashes, CRLF flattening, line endings, and the row-count footer. This keeps normal preview output byte-identical while preventing header-driven amplification. Empty-file previews also honor their output budget.

Stacked on #1926; only CSV preview budgeting and its tests are new here.

Testing

  • Before the fix: the bounded public-extractor regression recorded more than 9 MiB of allocation and failed its 1 MiB ceiling.
  • uv run pytest tests/document_ingestion/test_csv_preview_budget.py tests/document_ingestion/test_csv_extractor.py -q --no-cov: 24 passed.
  • Exact-byte budget tests cover empty, ASCII, escaped Unicode, CRLF, and ragged rows without mocks.
  • just fast-check: passed, including repository type checking.
  • just doctor: passed sandboxed write/index/search self-test.

Risks / Follow-ups

No new budget value or file-size policy: the existing CsvLimits.max_output_bytes now applies before output construction. The source and field limits continue to bound decoding and parsing.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T21:15:45.735648Z 6be07ae PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Base automatically changed from codex/security-markdown-token-work to main October 28, 2026 22:23
@phernandez
phernandez changed the base branch from codex/security-markdown-token-work to main October 28, 2026 22:23
@phernandez
phernandez merged commit ad7e44d into main Oct 28, 2026
50 checks passed
@phernandez
phernandez deleted the codex/security-csv-preview-budget branch October 28, 2026 22:24
phernandez added a commit that referenced this pull request Oct 28, 2026
)

## Why

Legacy upload normalizes literal POSIX backslashes into separators
without validating the resulting destination. A real temporary filename
`safe\..\..\other-project\leak.md` became
`safe/../../other-project/leak.md`; the HTTP client dispatched its PUT
to `/webdav/other-project/leak.md`. Fixes #1905.

## What Changed

Validate every destination using the shared portable relative-path
contract before sizing, dry-run reporting, or any authenticated request.
Reject the batch when a destination carries traversal, a drive, or an
absolute root.

## Implementation Details

Reject literal backslash filenames instead of remapping them to another
remote key. Convert native directory separators with Path.as_posix(),
then use the shared portable path-value validator with
filename-preserving behavior. This preserves distinct edge-space and
Unicode filename spellings. Skip archive validation because archives
never reach dispatch. Cover both directory discovery and explicitly
selected files. Regression tests run real files and a FastAPI HTTP
receiver through ASGITransport, without mocking upload behavior.

Stacked on #1927; only upload destination validation and its tests are
new here.

## Testing

- Before the fix: both public upload regressions failed; the directory
case reached the wrong project route.
- `uv run pytest tests/cli/cloud/test_upload_destination.py
tests/cli/cloud/test_upload_symlinks.py
tests/cli/cloud/test_upload_path.py tests/cli/test_upload.py -q
--no-cov`: 30 passed.
- Additional review regression: both ordinary backslash filename cases
failed before the fix; 10 focused upload tests pass after it.
- Review follow-up: whitespace-only files/components and skipped
backslash archives failed before the fix; 56 upload/path tests pass. The
shared validator is reused here without trimming names.
- Literal-colon follow-up: five real HTTP regressions failed before the
fix. 62 upload/path tests, 23 focused colon-policy tests, and 332
combined utility/filter/ZIP/upload/sink tests pass on the updated stack.
- `just fast-check`: passed, including repository type checking.
- `just doctor`: passed sandboxed write/index/search self-test.

## Risks / Follow-ups

A client-side route escape is reproduced, not a hosted authorization
bypass: server-side project authorization is still a separate boundary.
Single-file and directory uploads reject unsupported literal
backslashes. Native upload filenames explicitly allow literal colons,
including one-letter prefixes, because these names are discovered
relative to the selected tree and URL-encoded. Path-reference callers
retain the default Windows-drive restriction. Filename spaces and
Unicode spelling are preserved; three added real HTTP regressions failed
before the spelling fix.

---------

Signed-off-by: phernandez <[email protected]>
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.

Bound projected CSV output before padding wide rows

1 participant