Repository navigation
fix(doc-preview): load authorized web fonts in HTML previews - #26849
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to No issue requiring a fix before merge was identified in the supplied review scope. Pre-merge checks |
|
Records the retained adapted contribution from #26629 in replacement PR #26849. Co-authored-by: noan98 <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
82a87a1e-59c1-4226-ac63-02b8181e72ba
📒 Files selected for processing (5)
src/main/browser/doc-preview-file-reader.test.tssrc/main/browser/doc-preview-file-reader.tssrc/shared/doc-preview-file-access.test.tssrc/shared/doc-preview-file-access.tssrc/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.
| ...FONT_FILE_MIME_TYPES, | ||
| '.pdf': 'application/pdf' | ||
| } |
There was a problem hiding this comment.
🗄️ 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.tsRepository: 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.tsRepository: 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 -40Repository: 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 }Co-authored-by: noan98 <[email protected]>
1f37940 to
3cb1554
Compare
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,.ttfor.otffile 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):
Testing
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
Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)