Skip to content

fix(navigator): handle null headers when adding CORS - #841

Open
ddfreiling wants to merge 2 commits into
readium:developfrom
ddfreiling:fix/navigator-headerless-assets
Open

ddfreiling wants to merge 2 commits into
readium:developfrom
ddfreiling:fix/navigator-headerless-assets

Conversation

@ddfreiling

Copy link
Copy Markdown
Contributor

Bug

Requesting an allowed asset whose file is missing from the APK can crash in WebViewServer.allowCors(): AndroidX returns a response without headers.

We encountered this after forgetting to build a helper script loaded when opening a publication. A missing asset should fail to load without crashing the app.

Fix

Use responseHeaders.orEmpty() in both WebView servers before adding CORS. Existing headers are preserved.

Validation

  • All 48 navigator tests pass, including one new regression test.
  • The regression reproduces the NPE without the fix and passes with it.
  • Both affected modules compile and pass ktlint.

Copilot AI balanced review requested due to automatic review settings October 17, 2026 12:04
@ddfreiling ddfreiling changed the title Fix/navigator headerless assets fix(navigator): handle null headers when adding CORS Oct 17, 2026

Copilot AI 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.

🟢 Approval recommended

Both fixes preserve existing-header behavior and address the reported crash, with a focused regression test and no identified blocking issues.

No open issues 🎉

What changed in this PR

Prevents missing allowed assets from crashing either WebView server when AndroidX returns a response without headers.

Changes:

  • Handles null response headers before adding CORS, preserving existing headers.
  • Adds a regression test for a missing allowed asset.
File Description
readium/​navigators/​web/​internals/​src/​main/​kotlin/​org/​readium/​navigator/​web/​internals/​server/​WebViewServer.kt Makes CORS handling null-safe.
readium/​navigator/​src/​test/​java/​org/​readium/​r2/​navigator/​epub/​WebViewServerTest.kt Tests missing-asset responses and CORS headers.
readium/​navigator/​src/​main/​java/​org/​readium/​r2/​navigator/​epub/​WebViewServer.kt Applies the same null-safe CORS fix.

Review effort: Balanced

This branch has not been deployed

No deployments
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.

2 participants