Skip to content

fix(proxy): add data: to font-src CSP to allow bundled KaTeX fonts#12070

Merged
mmattel merged 3 commits intoowncloud:masterfrom
paul43210:fix/csp-font-src
Mar 11, 2026
Merged

fix(proxy): add data: to font-src CSP to allow bundled KaTeX fonts#12070
mmattel merged 3 commits intoowncloud:masterfrom
paul43210:fix/csp-font-src

Conversation

@paul43210
Copy link
Copy Markdown
Contributor

@paul43210 paul43210 commented Feb 28, 2026

Problem

The bundled Web UI CSS (services/web/assets/core/assets/style-*.css, sourced from the owncloud/web release tarball) contains an inlined KaTeX math font (KaTeX_Size3) as a data:font/woff2;base64,... URI. This is used by the md-editor component for formula rendering.

The default proxy CSP in services/proxy/pkg/config/csp.yaml sets font-src: 'self', which blocks data: URIs. This causes the following console error on every page load for all oCIS users:

Loading the font 'data:font/woff2;base64,d09GMgABAAAAAA4oAA...'
violates the following Content Security Policy directive: "font-src 'self'".
The action has been blocked.

Fix

Add data: to the font-src directive in the default CSP, consistent with how img-src already allows data: URIs.

Note for users with custom CSP files

This fix updates the embedded default CSP. Users who have set PROXY_CSP_CONFIG_FILE_LOCATION to point to a custom CSP YAML file will need to manually add - 'data:' under their font-src directive, as custom files take precedence over the embedded default.

Root cause

The root cause is that the owncloud/web build pipeline inlines the KaTeX font as base64 in the CSS bundle (likely via Vite's assetsInlineLimit). A complementary fix in the owncloud/web repository to emit the font as a separate .woff2 file instead of inlining it would eliminate the need for data: in font-src entirely, but that is out of scope for this PR.

@update-docs
Copy link
Copy Markdown

update-docs Bot commented Feb 28, 2026

Thanks for opening this pull request! The maintainers of this repository would appreciate it if you would create a changelog item based on your changes.

@mmattel
Copy link
Copy Markdown
Contributor

mmattel commented Mar 4, 2026

Fixes one issue referenced in OCISDEV-667
@LukasHirt can you take a look

@mmattel mmattel requested a review from LukasHirt March 4, 2026 12:18
@mmattel mmattel force-pushed the fix/csp-font-src branch from 181230a to 4b3052b Compare March 4, 2026 12:46
@mmattel
Copy link
Copy Markdown
Contributor

mmattel commented Mar 4, 2026

CI errors are unrelated, S3 backend issues...

Copy link
Copy Markdown
Contributor

@LukasHirt LukasHirt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general I would love to see a fix loading the fonts as actual assets in Web but since inlined fonts are not really a security nono I think this would be a good first step.

Fixing the fonts might involve a bit more work as katex has this really hard coded in the css files so probably some upstream contribution would be required.

I'll restart the CI in the meantime to hopefully get it green.

@mmattel mmattel force-pushed the fix/csp-font-src branch 2 times, most recently from b0aa884 to bb0ef32 Compare March 6, 2026 10:39
@mmattel mmattel enabled auto-merge March 6, 2026 10:55
@mmattel mmattel force-pushed the fix/csp-font-src branch from bb0ef32 to b4b5816 Compare March 6, 2026 13:22
@mmattel mmattel disabled auto-merge March 6, 2026 15:04
@mmattel mmattel enabled auto-merge March 9, 2026 10:04
@LukasHirt
Copy link
Copy Markdown
Contributor

@paul43210 the CI keeps failing in the same tests. Could you please try to rebase the PR? Maybe that will solve it?

auto-merge was automatically disabled March 9, 2026 23:31

Head branch was pushed to by a user without write access

@paul43210
Copy link
Copy Markdown
Contributor Author

@LukasHirt Rebased onto latest master as requested. Unfortunately Drone is still failing on the same tests.

All tests pass locally — the full ./services/proxy/... test suite and build both succeed. The change is only a CSP YAML config file and a changelog entry, so there's no Go code that could cause test failures.

As @mmattel noted earlier, the failures appear to be S3 backend infrastructure issues on the Drone side. Let me know if there's anything else I can do to help get this green, or if a maintainer can restart the pipeline.

@LukasHirt
Copy link
Copy Markdown
Contributor

@paul43210 the S3 failure has been resolved for several past runs. The issue is now in the Core-API-6 tests. It seems that the CSP is actually checked in some test:

Failed step: And the following headers should be set
        WebDav::theFollowingHeadersShouldBeSet Expected value for header 'Content-Security-Policy' was 'child-src 'self'; connect-src 'self' blob: https://raw.githubusercontent.com/owncloud/awesome-ocis/; default-src 'none'; font-src 'self'; frame-ancestors 'self'; frame-src 'self' blob: https://embed.diagrams.net/; img-src 'self' data: blob: https://raw.githubusercontent.com/owncloud/awesome-ocis/; manifest-src 'self'; media-src 'self'; object-src 'self' blob:; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'', but got 'child-src 'self'; connect-src 'self' blob: https://raw.githubusercontent.com/owncloud/awesome-ocis/; default-src 'none'; font-src 'self' data:; frame-ancestors 'self'; frame-src 'self' blob: https://embed.diagrams.net/; img-src 'self' data: blob: https://raw.githubusercontent.com/owncloud/awesome-ocis/; manifest-src 'self'; media-src 'self'; object-src 'self' blob:; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'' instead.
        Failed asserting that two strings are equal.
        --- Expected
        +++ Actual
        @@ @@
        -'child-src 'self'; connect-src 'self' blob: https://raw.githubusercontent.com/owncloud/awesome-ocis/; default-src 'none'; font-src 'self'; frame-ancestors 'self'; frame-src 'self' blob: https://embed.diagrams.net/; img-src 'self' data: blob: https://raw.githubusercontent.com/owncloud/awesome-ocis/; manifest-src 'self'; media-src 'self'; object-src 'self' blob:; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline''
        +'child-src 'self'; connect-src 'self' blob: https://raw.githubusercontent.com/owncloud/awesome-ocis/; default-src 'none'; font-src 'self' data:; frame-ancestors 'self'; frame-src 'self' blob: https://embed.diagrams.net/; img-src 'self' data: blob: https://raw.githubusercontent.com/owncloud/awesome-ocis/; manifest-src 'self'; media-src 'self'; object-src 'self' blob:; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline''

This means that the test failure is not a random one and the test needs to be adjusted to expect the new value as well.

paul43210 and others added 2 commits March 10, 2026 11:08
The bundled Web UI CSS (from owncloud/web) inlines the KaTeX_Size3 font
as a base64 data:font/woff2 URI. The default CSP sets font-src to 'self'
only, which blocks these data URIs and produces a console error on every
page load:

  Loading the font 'data:font/woff2;base64,...' violates the following
  Content Security Policy directive: "font-src 'self'".

Add 'data:' to font-src, matching the existing pattern where img-src
already permits data: URIs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mmattel mmattel mentioned this pull request Mar 10, 2026
9 tasks
…hange

Update acceptance tests and all deployment example CSP configs to include
'data:' in font-src, consistent with the default csp.yaml change.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@paul43210
Copy link
Copy Markdown
Contributor Author

@LukasHirt Good catch — thanks for digging into the actual test failure.

I've pushed a fix in d4367fb2 that updates:

  • tests/acceptance/features/coreApiWebdavOperations/downloadFile.feature — both CSP header assertions now expect font-src 'self' data:
  • tests/config/drone/csp.yaml — added data: to font-src in the Drone test config
  • All 7 deployment example CSP configs under deployments/examples/ — updated for consistency

Core-API-6 should pass now. Let me know if anything else is needed.

@sonarqubecloud
Copy link
Copy Markdown

@mmattel mmattel merged commit c65dff7 into owncloud:master Mar 11, 2026
5 checks passed
ownclouders pushed a commit that referenced this pull request Mar 11, 2026
fix(proxy): add data: to font-src CSP to allow bundled KaTeX fonts
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.

3 participants