Skip to content

Fix CSP violations blocking jQuery, fonts, and search on production site#165

Closed
vinooganesh wants to merge 2 commits intoapache:productionfrom
vinooganesh:vinooganesh/fix-csp-violations
Closed

Fix CSP violations blocking jQuery, fonts, and search on production site#165
vinooganesh wants to merge 2 commits intoapache:productionfrom
vinooganesh:vinooganesh/fix-csp-violations

Conversation

@vinooganesh
Copy link
Copy Markdown
Collaborator

Closes #163

The production site at parquet.apache.org is served behind Apache's Content Security Policy, which blocks resources from external CDNs. This causes broken styling, jQuery is not defined errors, and completely non-functional search on the live site, even though everything works fine in local dev.

This PR eliminates all external resource dependencies so the site works identically in both environments.

What was broken

Blocked resource Effect on production site
code.jquery.com/jquery-3.7.1.min.js jQuery is not defined — breaks all JS functionality
fonts.googleapis.com/css?family=Open+Sans Font fails to load, falls back unpredictably
cdn.jsdelivr.net/npm/@docsearch/css@3.8.2 Search styling missing
cdn.jsdelivr.net/npm/@docsearch/js@3.8.2 docsearch is not defined — search completely broken

What this PR does

Vendor jQuery locally (originally @alamb 's idea, h/t to him) - Downloaded jquery-3.7.1.min.js to static/js/ and created a project-level override of Docsy's head.html partial to load it from there instead of the CDN. Same version, just self-hosted.

Replace Algolia DocSearch with Lunr offline search - Algolia was doubly broken: blocked by CSP and the API keys were removed in a prior commit. Switched to Docsy's built-in Lunr search which is fully client-side with no external dependencies. Also bumped max results to 25 and excerpt length to 200 chars for better usability.

Disable Google Fonts - Set $td-enable-google-fonts: false so the site uses Bootstrap's system font stack instead of trying to fetch Open Sans from Google. Fonts render immediately with no network request.

Files changed

  • hugo.toml - Enable offline search, remove Algolia config
  • assets/scss/_variables_project.scss - Disable Google Fonts
  • layouts/partials/head.html (new) - Override Docsy's head to load jQuery and Lunr locally
  • layouts/partials/scripts.html (new) - Override Docsy's scripts to remove Algolia JS
  • layouts/partials/hooks/head-end.html - Remove Algolia CSS hook
  • layouts/partials/hooks/body-end.html - Remove Algolia JS hook
  • static/js/jquery-3.7.1.min.js (new) - Vendored jQuery
  • static/js/lunr-2.3.9.min.js (new) - Vendored Lunr

How I verified

Andrew mentioned he wanted to make sure dev matched prod - I built the site from the clean production branch (before) and confirmed all 4 external CDN references are present. Built again with these changes (after) and confirmed zero external resource loads remain. The dev server serves all JS, CSS, and the search index locally, and search returns results.

Also, no Docsy version changes here, stays on v0.12.0.

Copy link
Copy Markdown
Collaborator

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thank you for this @vinooganesh

I am not sure about some of these changes -- maybe we can break them into separate PRs so we can merge the non controversial stuff (like disabling google fonts and removing the body-end and head-end partials)

And then we can have another PR discussion about jquery

@@ -0,0 +1,43 @@
{{/* cSpell:ignore docsearch opengraph outputformat */ -}}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we add some comments to this file explaining what it does / is used for?

Comment thread layouts/partials/scripts.html Outdated
},
};
</script>
<script src="https://cdn.jsdelivr.net/npm/markmap-autoloader"></script>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do we also need to vendor this URL?

Comment thread hugo.toml

# Enable Lunr.js offline search
offlineSearch = false
offlineSearch = true
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

How does the Lunr.js search work? I loaded this page locally and it seems like it still tries to use algolia

Image Image

$primary: #56a4ed
$primary: #56a4ed;

// Disable Google Fonts to comply with apache.org Content Security Policy
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe we can create a separate PR just for this change

@@ -0,0 +1,2 @@
/*! jQuery v3.7.1 | (c) OpenJS Foundation and other contributors | jquery.org/license */
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I do wonder why we need jquery -- the current site looks ok without it 🤔

- Add explanatory comments to head.html and scripts.html overrides
- Remove markmap-autoloader CDN block from scripts.html (not enabled, blocked by CSP)
- Fix scripts.html formatting that was mangled by an auto-formatter
- Bump offlineSearchMaxResults to 25 and offlineSearchSummaryLength to 200
@vinooganesh
Copy link
Copy Markdown
Collaborator Author

Good call @alamb ! I'll split these into separate PRs

@vinooganesh vinooganesh deleted the vinooganesh/fix-csp-violations branch February 13, 2026 19:24
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.

Consider vendoring jquery/css or removing their use from the site

2 participants