Skip to content

fix(doc-preview): load authorized web fonts in HTML previews - #26849

Merged
OrcaWin merged 1 commit into
mainfrom
nwparker/obvious-preview-fonts-10-09
Oct 11, 2026
Merged

OrcaWin merged 1 commit into
mainfrom
nwparker/obvious-preview-fonts-10-09

Conversation

@nwparker

@nwparker nwparker commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

An HTML file opened in a preview from a paired machine or SSH workspace can now use its own web fonts. Before, the font files were refused and the page fell back to a default font.

What Changed

Before: a preview of a remote HTML page that loads a .woff, .woff2, .ttf or .otf file showed the fallback font, and the font request failed with "unsupported file type" (HTTP 415).

After: the font loads and the page renders as written.

Mechanism: the host-side reader that serves preview files (readAuthorizedDocPreviewFile) only sent images and PDFs as raw bytes. Every other file was read as text, and a binary file read as text came back empty. Fonts are now in the reader's binary list, so they come back as base64 with their font MIME type. One small table (src/shared/font-file-extensions.ts) now supplies the font types to both the host reader and the preview's response headers, which already listed them.

Why

The preview already allows these fonts in its response headers; only the host reader was missing them. Adding them to the existing reader keeps the same path checks, folder permissions and size limits, with no new way to move files and no wider directory access. Original diagnosis and fix proposed by @noan98 in #26629.

Linked Issue

Fixes #26614

Visual Proof

Before / after of the same HTML file (heading uses a bundled web font):

Before After
Fallback font Custom font loaded

Testing

  • I manually tested these changes locally (earlier revision; hidden macOS render check)
  • Automated tests added/updated

New reader tests cover all four font types (including an upper-case extension), the binary size limit and folder authorization; they fail on current main and pass with this change. Doc-preview reader suites pass.

Review

Self-review plus an independent read-only review; no blocking issues found.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Security: same path canonicalization, symlink refusal, folder grants and byte caps as images. The agent-attachment caller of this reader still accepts images only.
  • Mixed versions: a newer host sends the existing base64 result shape, which older desktop clients already decode; an older host still returns the explicit "cannot send this file type" result. No wire fields change.
  • No platform-specific code.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@nwparker
nwparker marked this pull request as ready for review October 9, 2026 11:36
@coderabbitai

coderabbitai Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2f0f7d25-8d17-4bdd-b3e5-a62e67dd601d


📥 Commits

Reviewing files that changed from the base of the PR and between 1f37940 and 3cb1554.



📒 Files selected for processing (1)
  • src/shared/doc-preview-file-access.test.ts


Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.




📝 Walkthrough
📝 Walkthrough

Walkthrough

The change adds a shared MIME type map for WOFF, WOFF2, TTF, and OTF files. Shared preview file access now reads recognized fonts as binary content and returns base64 data with the MIME type. The browser reader uses the shared map. Tests cover authorized reads, authorization failures, and size limits.



Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 3cb15

No issue requiring a fix before merge was identified in the supplied review scope.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check Passed Issue #26614 requires previewed .woff and .woff2 files to load as binary assets. It also requests the same treatment for .ttf and .otf files. The PR adds all four MIME types to the authorized …
Out of Scope Changes check Passed The changes remain within issue #26614. The shared font MIME map supports the reader and preview content types. The tests verify the requested behavior and preserve authorization and size-limit checks…
Title check Passed The title clearly and concisely describes the main change: loading authorized web fonts in HTML previews.
Description check Passed The description is complete and follows the repository template. It explains the user impact, implementation, rationale, linked issue, visual proof, testing, security considerations, compatibility, an…

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR



  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

nwparker added a commit that referenced this pull request Oct 9, 2026
Records the retained adapted contribution from #26629 in replacement PR #26849.

Co-authored-by: noan98 <[email protected]>

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 82a87a1e-59c1-4226-ac63-02b8181e72ba
📥 Commits

Reviewing files that changed from the base of the PR and between 049bf80 and 1f37940.

📒 Files selected for processing (5)
  • src/main/browser/doc-preview-file-reader.test.ts
  • src/main/browser/doc-preview-file-reader.ts
  • src/shared/doc-preview-file-access.test.ts
  • src/shared/doc-preview-file-access.ts
  • src/shared/font-file-extensions.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

Comment on lines +33 to 35
...FONT_FILE_MIME_TYPES,
'.pdf': 'application/pdf'
}

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.

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '1,180p' src/shared/doc-preview-file-access.ts
sed -n '55,110p' src/main/browser/doc-preview-file-reader.ts
sed -n '125,180p' src/main/browser/doc-preview-file-reader.ts
rg -n "symlink|realpath|authorizedRoots|openAuthorizedDocPreviewTarget" src/shared/doc-preview-file-access.ts src/shared/doc-preview-file-access.test.ts

Repository: stablyai/orca

Length of output: 10406


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- path resolution and callers ---'
rg -n -F --glob '*.ts' -- 'resolveDocPreviewCandidatePath' src/main src/shared
rg -n -F --glob '*.ts' -- 'resolveDocPreviewTargetPath' src/main src/shared
printf '%s\n' '--- symlink-related tests ---'
sed -n '1,150p' src/shared/doc-preview-file-access.test.ts
printf '%s\n' '--- browser reader complete relevant declarations ---'
sed -n '1,235p' src/main/browser/doc-preview-file-reader.ts
printf '%s\n' '--- preview protocol response ---'
sed -n '80,125p' src/main/browser/doc-preview-protocol.ts

Repository: stablyai/orca

Length of output: 21012


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- grant registry path declarations ---'
sed -n '120,245p' src/main/browser/doc-preview-grant-registry.ts
printf '%s\n' '--- remaining shared reader tests ---'
sed -n '145,360p' src/shared/doc-preview-file-access.test.ts
printf '%s\n' '--- MIME and font usages ---'
rg -n -F --glob '*.ts' -- 'mimeType' src/shared src/main/browser | head -80
rg -n -F --glob '*.ts' -- 'font/woff2' src | head -40

Repository: stablyai/orca

Length of output: 12138


Use the returned MIME type for binary preview responses.

An authorized .woff2 symlink can point to a .ttf file in the same granted directory. The shared reader returns TTF bytes with mimeType: 'font/ttf', but toOutcome sends them as font/woff2 because it uses the requested path. The browser can reject the font because the response MIME type does not match the bytes.

Suggested fix
  if (source.content) {
-    return { ok: true, bytes: Buffer.from(source.content, 'base64'), contentType }
+    return {
+      ok: true,
+      bytes: Buffer.from(source.content, 'base64'),
+      contentType: source.mimeType ?? contentType
+    }
  }
...
  return source.mimeType
-    ? { ok: true, bytes: Buffer.alloc(0), contentType }
+    ? { ok: true, bytes: Buffer.alloc(0), contentType: source.mimeType }

@OrcaWin
OrcaWin force-pushed the nwparker/obvious-preview-fonts-10-09 branch from 1f37940 to 3cb1554 Compare October 11, 2026 06:53
@OrcaWin OrcaWin changed the title fix: load authorized fonts in HTML previews fix(doc-preview): load authorized web fonts in HTML previews Oct 11, 2026
@OrcaWin
OrcaWin merged commit 38aa54f into main Oct 11, 2026
31 checks passed
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.

[Bug]: HTML document preview drops web fonts (.woff2/.woff) — runtime reader returns them empty, preview answers 415 unsupported-asset

2 participants