Skip to content

fix: harden runtime file URL handling - #59

Merged
alekswebnet merged 1 commit into
masterfrom
fix/runtime-url-followups
Oct 19, 2026
Merged

alekswebnet merged 1 commit into
masterfrom
fix/runtime-url-followups

Conversation

@alekswebnet

Copy link
Copy Markdown
Collaborator

Summary

Small follow-ups from the review of #57 (individual runtime file URL attributes).

  • Explicit attribute table. Attribute names were derived from object keys by a regex, so pdfjs-lib-src, viewer-css-src etc. appeared nowhere in the source, and renaming a key silently renamed a public attribute. DIST_FILE_NAMES and DEFAULT_RUNTIME_FILE_URLS are merged into one RUNTIME_FILES table that lists each file's attribute, dist file name and bundled default.
  • Read runtime URLs once per build. buildViewerEntry (CSP and stylesheet links) and buildViewerApp (script injection) each re-read the attributes, with awaits 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 new buildViewer() reads the URLs once and passes them to both steps. It also replaces the init code that was duplicated in connectedCallback and the locale rebuild.
  • Escape stylesheet URLs in the srcdoc. getFullPath returns 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.
  • README: all runtime files must come from the same package release as the element.

applyViewerOptions still reads worker-src live, because that attribute is meant to be updatable at runtime.

Not included

These change behavior, so they need a decision first:

  • Resolving relative URLs against document.baseURI instead of location.href, for pages with <base href>. This would also change how src resolves.
  • Making worker-src and the other four runtime file attributes behave the same way. Today only worker-src updates at runtime.

Tests

Three new tests:

  • The CSP includes the origin of each override (pdfjs-lib-src, viewer-src, viewer-css-src, theme-css-src). Each one uses its own .invalid host, so no network access is needed.
  • An attribute set right after connection doesn't change the build that is already running.
  • An invalid theme-css-src containing markup stays a single href and injects nothing.

The last two fail without the fix. The full suite passes (20/20), and pnpm build succeeds.

🤖 Generated with Claude Code

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>
@alekswebnet alekswebnet self-assigned this Oct 19, 2026
@alekswebnet
alekswebnet merged commit 57bc1c3 into master Oct 19, 2026
6 checks passed
@alekswebnet
alekswebnet deleted the fix/runtime-url-followups branch October 19, 2026 18:43
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