Repository navigation
fix: harden runtime file URL handling - #59
Merged
Merged
Conversation
Follow-ups from the review of #57: - Replace the regex that derived attribute names from object keys with an explicit RUNTIME_FILES table (attribute, dist file name, default). - Read runtime file URLs once per build, so the srcdoc CSP and the files it loads always come from the same values. - Escape stylesheet URLs written into the srcdoc markup; values that are not valid URLs are passed through as written. - Document that all runtime files must come from the same release. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Small follow-ups from the review of #57 (individual runtime file URL attributes).
pdfjs-lib-src,viewer-css-srcetc. appeared nowhere in the source, and renaming a key silently renamed a public attribute.DIST_FILE_NAMESandDEFAULT_RUNTIME_FILE_URLSare merged into oneRUNTIME_FILEStable that lists each file's attribute,distfile name and bundled default.buildViewerEntry(CSP and stylesheet links) andbuildViewerApp(script injection) each re-read the attributes, withawaits in between. An attribute changed mid-build could produce a CSP for one origin and a script from another, which the CSP then blocks. A newbuildViewer()reads the URLs once and passes them to both steps. It also replaces the init code that was duplicated inconnectedCallbackand the locale rebuild.getFullPathreturns the raw value when it isn't a valid URL, and that value went straight into<link href="...">. A value containing"could add markup to the viewer document. Both stylesheet hrefs are now attribute-escaped.applyViewerOptionsstill readsworker-srclive, because that attribute is meant to be updatable at runtime.Not included
These change behavior, so they need a decision first:
document.baseURIinstead oflocation.href, for pages with<base href>. This would also change howsrcresolves.worker-srcand the other four runtime file attributes behave the same way. Today onlyworker-srcupdates at runtime.Tests
Three new tests:
pdfjs-lib-src,viewer-src,viewer-css-src,theme-css-src). Each one uses its own.invalidhost, so no network access is needed.theme-css-srccontaining markup stays a singlehrefand injects nothing.The last two fail without the fix. The full suite passes (20/20), and
pnpm buildsucceeds.🤖 Generated with Claude Code