Skip to content

Commit a51d08e

Browse files
committed
fine tune
1 parent fd3246c commit a51d08e

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

services/context/context_template.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,15 @@ func (c TemplateContext) CspScriptNonce() (ret string) {
129129

130130
func (c TemplateContext) HeadMetaContentSecurityPolicy() template.HTML {
131131
return template.HTML(`<meta http-equiv="Content-Security-Policy" content="` +
132-
`default-src *` + // allow all by default (the same as old releases with no CSP)
132+
// allow all by default (the same as old releases with no CSP)
133+
// "data:" is used to load the manifest in head (maybe also need to be refactored in the future)
134+
// maybe some images are also loaded by "data:", need to investigate
135+
`default-src * data:;` +
136+
137+
// enforce nonce for all scripts, disallow inline scripts
133138
`script-src * 'nonce-` + c.CspScriptNonce() + `';` +
134-
`style-src * 'unsafe-inline';` + // it seems that Vue needs it, need to investigate
139+
140+
// it seems that Vue needs the unsafe-inline, need to investigate
141+
`style-src * 'unsafe-inline';` +
135142
`">`)
136143
}

web_src/js/features/repo-issue-pull.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ async function initRepoPullRequestMergeForm(box: HTMLElement) {
6969
}
7070

7171
function executeScripts(elem: HTMLElement) {
72-
const scriptNonce = document.querySelector('head script[nonce]')!.getAttribute('nonce')!;
72+
// find any existing nonce value from the current page and apply it to the new script
73+
const scriptNonce = document.querySelector('script[nonce]')!.getAttribute('nonce')!;
7374
for (const oldScript of elem.querySelectorAll('script')) {
7475
// TODO: that's the only way to load the data for the merge form. In the future
7576
// we need to completely decouple the page data and embedded script

0 commit comments

Comments
 (0)