Office preview WebView may break under strict Content-Security-Policy #2

Closed
opened 2026-04-25 04:18:16 +00:00 by msdong · 0 comments
msdong commented 2026-04-25 04:18:16 +00:00 (Migrated from codeberg.org)

Problem

The app renders Office document previews (Word, Excel, etc.) inside a WebView (ImagePreviewDialog.kt, around line 620). The server recently added Content-Security-Policy headers to all responses. If the CSP on the Office preview endpoint (/api/v1/files/{id}/office) is strict enough to block inline scripts or restrict script-src, the WebView will silently fail to render the document — no crash, just a blank or broken preview.

Affected component

app/src/main/java/com/dumango/filecloud/ui/components/ImagePreviewDialog.kt

  • AuthenticatedWebView inner class (approx. lines 581–650)
  • settings.javaScriptEnabled = true + settings.domStorageEnabled = true are set
  • The WebView intercepts requests to inject the Authorization header but does not inspect or relax CSP headers

Expected behaviour

  • Office previews continue to render correctly regardless of server-side CSP.
  • If CSP causes a load failure, show a clear fallback message ("Vorschau nicht verfügbar" / "Preview not available") instead of a blank screen.

Suggested fixes

  1. Server-side (preferred): Ensure the Office preview endpoint (/office) serves a CSP that is compatible with WebView rendering (allow the scripts required by the preview renderer).
  2. Client-side fallback: Wrap the WebView onPageFinished / onReceivedError callbacks to detect blank/failed loads and display a fallback UI.
  3. Client-side hardening: Use WebViewClient.onReceivedHttpError to catch CSP-blocked responses (HTTP 200 with no content) and show the fallback.

Context

Discovered during compatibility audit against server security-hardening branch (security-hardening-2026-04). No crash — purely a silent rendering failure risk.

## Problem The app renders Office document previews (Word, Excel, etc.) inside a `WebView` (`ImagePreviewDialog.kt`, around line 620). The server recently added `Content-Security-Policy` headers to all responses. If the CSP on the Office preview endpoint (`/api/v1/files/{id}/office`) is strict enough to block inline scripts or restrict `script-src`, the WebView will silently fail to render the document — no crash, just a blank or broken preview. ## Affected component `app/src/main/java/com/dumango/filecloud/ui/components/ImagePreviewDialog.kt` - `AuthenticatedWebView` inner class (approx. lines 581–650) - `settings.javaScriptEnabled = true` + `settings.domStorageEnabled = true` are set - The WebView intercepts requests to inject the `Authorization` header but does **not** inspect or relax CSP headers ## Expected behaviour - Office previews continue to render correctly regardless of server-side CSP. - If CSP causes a load failure, show a clear fallback message (*"Vorschau nicht verfügbar"* / *"Preview not available"*) instead of a blank screen. ## Suggested fixes 1. **Server-side (preferred):** Ensure the Office preview endpoint (`/office`) serves a CSP that is compatible with WebView rendering (allow the scripts required by the preview renderer). 2. **Client-side fallback:** Wrap the WebView `onPageFinished` / `onReceivedError` callbacks to detect blank/failed loads and display a fallback UI. 3. **Client-side hardening:** Use `WebViewClient.onReceivedHttpError` to catch CSP-blocked responses (HTTP 200 with no content) and show the fallback. ## Context Discovered during compatibility audit against server security-hardening branch (`security-hardening-2026-04`). No crash — purely a silent rendering failure risk.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
msdong/dumangofilecloud_android#2
No description provided.