-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add Content-Security-Policy header and externalize theme-init #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b11f31f
feat: add Content-Security-Policy header and externalize theme-init
clean6378-max-it 15d8490
fix: wire UI handlers for CSP compliance and strengthen policy tests
clean6378-max-it 35275f0
fix: harden CSP policy and address PR review feedback
clean6378-max-it 67ef87e
docs: clarify style-src unsafe-inline scope in architecture.md
clean6378-max-it d76e856
test: add coverage for CSP theme-init scripts and navbar handlers
clean6378-max-it File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| /* Initial hljs stylesheet for light mode — must match HLJS_THEME_SHEETS.light | ||
| in static/js/shared/theme.js (runtime swaps use applyHljsTheme). */ | ||
| (function () { | ||
| var t = document.documentElement.getAttribute('data-theme') || 'dark'; | ||
| if (t !== 'light') return; | ||
| var link = document.getElementById('hljs-theme'); | ||
| if (!link) return; | ||
| // Set integrity before href — browser reads integrity at fetch time (see applyHljsTheme). | ||
| link.integrity = 'sha512-0aPQyyeZrWj9sCA46UlmWgKOP0mUipLQ6OZXu8l4IcAmD2u31EPEy9VcIMvl7SoAaKe8bLXZhYoMaE/in+gcgA=='; | ||
|
clean6378-max-it marked this conversation as resolved.
|
||
| link.href = 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github.min.css'; | ||
| })(); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
|
|
||
| describe('hljs-theme-init.js', () => { | ||
| beforeEach(() => { | ||
| vi.resetModules(); | ||
| document.documentElement.setAttribute('data-theme', 'dark'); | ||
| document.body.innerHTML = ''; | ||
| }); | ||
|
|
||
| it('does nothing when data-theme is dark', async () => { | ||
| document.body.innerHTML = '<link id="hljs-theme" href="https://example.com/dark.css" />'; | ||
| await import('./hljs-theme-init.js'); | ||
| const link = document.getElementById('hljs-theme'); | ||
| expect(link.href).toContain('dark.css'); | ||
| expect(link.getAttribute('integrity')).toBeNull(); | ||
| }); | ||
|
|
||
| it('sets light-theme CDN href and SRI when data-theme is light', async () => { | ||
| document.documentElement.setAttribute('data-theme', 'light'); | ||
| document.body.innerHTML = '<link id="hljs-theme" href="about:blank" />'; | ||
| await import('./hljs-theme-init.js'); | ||
| const link = document.getElementById('hljs-theme'); | ||
| expect(link.href).toContain('github.min.css'); | ||
| expect(link.integrity).toBe( | ||
| 'sha512-0aPQyyeZrWj9sCA46UlmWgKOP0mUipLQ6OZXu8l4IcAmD2u31EPEy9VcIMvl7SoAaKe8bLXZhYoMaE/in+gcgA==', | ||
| ); | ||
| }); | ||
|
|
||
| it('no-ops when hljs-theme link is missing', async () => { | ||
| document.documentElement.setAttribute('data-theme', 'light'); | ||
| await import('./hljs-theme-init.js'); | ||
| expect(document.getElementById('hljs-theme')).toBeNull(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.