Skip to content

improvement(files): harden untrusted document preview and parsing - #6420

Merged
waleedlatif1 merged 3 commits into
stagingfrom
docx-preview-hardening
Aug 8, 2026
Merged

improvement(files): harden untrusted document preview and parsing#6420
waleedlatif1 merged 3 commits into
stagingfrom
docx-preview-hardening

Conversation

@waleedlatif1

@waleedlatif1 waleedlatif1 commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Tighten the render options the docx preview passes to docx-preview so it only renders the document body, and drop embedded frames/plugin elements from rendered content
  • Tighten the OOXML archive size guard: cap the largest single XML part and lower the total expanded-size ceiling so oversized archives are rejected before a parser materializes them

Type of Change

  • Improvement

Testing

Unit tests for the sanitizer pass and the archive guard (per-entry cap, total cap, media-part scoping); measured against crafted inputs locally. Type-check and lint clean.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Aug 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Aug 8, 2026 7:37pm

Request Review

@cursor

cursor Bot commented Aug 8, 2026

Copy link
Copy Markdown

PR Summary

High Risk
Changes directly address XSS via rendered document content and zip-bomb/OOM in the untrusted file parsing pipeline; incorrect limits could reject legitimate large Office files or leave a bypass.

Overview
Hardens untrusted DOCX preview and OOXML parse paths so crafted files are less likely to run script in the app origin or OOM the worker.

DOCX preview turns off renderAltChunks in docx-preview and, after render, runs stripEmbeddedFrames alongside existing hyperlink sanitization. That helper removes iframe, object, and embed from the preview DOM so srcdoc iframes cannot inherit the app origin and execute embedded script.

OOXML zip guard adds a per-entry declared uncompressed ceiling (default 64 MiB) on every central-directory entry—not only .xml names—because OPC relationship targets can point at arbitrarily named parts that parsers still materialize into a DOM. Default total expanded cap drops from 1 GiB to 150 MiB so oversized archives are rejected before mammoth/SheetJS inflate them. Tests cover per-entry vs total rejection, non-.xml parts, and default-limit behavior.

Reviewed by Cursor Bugbot for commit b4bcd00. Configure here.

@greptile-apps

greptile-apps Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR hardens untrusted Office-document handling in both browser previews and server-side parsing.

  • Disables DOCX altChunk rendering and removes embedded frame/plugin elements from rendered previews.
  • Adds a 64 MiB per-entry OOXML limit and reduces the total expanded-size limit to 150 MiB.
  • Extends archive-guard and DOM-sanitization coverage with focused tests.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/docx-preview.tsx Disables altChunk rendering and applies the new embedded-element cleanup after DOCX rendering; no eligible follow-up defect was established.
apps/sim/lib/core/security/url-safety.ts Adds a focused DOM cleanup utility that removes iframe, object, and embed elements from untrusted rendered content.
apps/sim/lib/file-parsers/zip-guard.ts Adds a per-entry expanded-size ceiling, lowers the aggregate ceiling, and applies the entry limit uniformly across archive parts.
apps/sim/lib/file-parsers/zip-guard.test.ts Covers aggregate and per-entry rejection, non-XML part handling, default limits, and ordinary-document acceptance.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  Upload[Untrusted Office document] --> Preview[DOCX browser preview]
  Upload --> Parse[OOXML parser path]
  Preview --> Options[Disable altChunk rendering]
  Options --> Render[Render document body]
  Render --> Sanitize[Sanitize links and remove frames/plugins]
  Sanitize --> Display[Display preview]
  Parse --> Inspect[Inspect ZIP central directory]
  Inspect --> EntryCap{Any entry over 64 MiB?}
  Inspect --> TotalCap{Total over 150 MiB?}
  EntryCap -->|Yes| Reject[Reject archive]
  TotalCap -->|Yes| Reject
  EntryCap -->|No| Validate[Validate compression and declared sizes]
  TotalCap -->|No| Validate
  Validate --> Parser[Run document parser]
Loading

Reviews (3): Last reviewed commit: "fix(files): apply the per-entry OOXML ca..." | Re-trigger Greptile

@waleedlatif1 waleedlatif1 changed the title improvement(files): harden the docx preview renderer improvement(files): harden untrusted document preview and parsing Aug 8, 2026
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

Comment thread apps/sim/lib/file-parsers/zip-guard.ts
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor 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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit b4bcd00. Configure here.

@waleedlatif1
waleedlatif1 merged commit 87b7b4b into staging Aug 8, 2026
30 checks passed
@waleedlatif1
waleedlatif1 deleted the docx-preview-hardening branch August 8, 2026 19:42
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.

1 participant