Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

resolve sha hash exemptions#525

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ShMcK merged 1 commit intomasterfromfix/sha-hash-exemptions
Nov 13, 2021
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletionsrc/commands.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,7 +33,6 @@ export const send = (action: T.Action): void => {
}

export const createCommands = (commandProps: CreateCommandProps): { [key: string]: any } => {
console.log(commandProps)
const { extensionPath, workspaceState } = commandProps
// React panel webview
let webview: any
Expand Down
19 changes: 16 additions & 3 deletionssrc/services/webview/render.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,6 +27,7 @@ async function render(panel: vscode.WebviewPanel, rootPath: string): Promise<voi

// used for CSP
const nonces: string[] = []
const hashes: string[] = []

// generate vscode-resource build path uri
const createUri = (_filePath: string): any => {
Expand All@@ -50,7 +51,12 @@ async function render(panel: vscode.WebviewPanel, rootPath: string): Promise<voi
// support additional CSP exemptions when CodeRoad is embedded
if (CONTENT_SECURITY_POLICY_EXEMPTIONS && CONTENT_SECURITY_POLICY_EXEMPTIONS.length) {
for (const exemption of CONTENT_SECURITY_POLICY_EXEMPTIONS.split(' ')) {
nonces.push(exemption)
// sha hashes should not be prefixed with 'nonce-'
if (exemption.match(/^sha/)) {
hashes.push(exemption)
} else {
nonces.push(exemption)
}
}
}

Expand All@@ -71,17 +77,24 @@ async function render(panel: vscode.WebviewPanel, rootPath: string): Promise<voi
}

// set CSP (content security policy) to grant permission to local files
// while blocking unexpected malicious network requests
const cspMeta: HTMLMetaElement = document.createElement('meta')
cspMeta.httpEquiv = 'Content-Security-Policy'

const wrapInQuotes = (str: string) => `'${str}'`
const nonceString = nonces.map((nonce: string) => wrapInQuotes(`nonce-${nonce}`)).join(' ')
const hashString = hashes.map(wrapInQuotes).join(' ')

cspMeta.content =
[
`default-src 'self'`,
`manifest-src ${hashString} 'self'`,
`connect-src https: http:`,
// @ts-ignore
`font-src ${panel.webview.cspSource} http: https: data:`,
// @ts-ignore
`img-src ${panel.webview.cspSource} https:`,
`script-src ${nonces.map((nonce) => `'nonce-${nonce}'`).join(' ')} data:`,
`script-src ${nonceString} ${hashString} data:`,
// @ts-ignore
`style-src ${panel.webview.cspSource} https: 'self' 'unsafe-inline'`,
].join('; ') + ';'
Expand All@@ -92,7 +105,7 @@ async function render(panel: vscode.WebviewPanel, rootPath: string): Promise<voi

// set view
panel.webview.html = html
} catch (error) {
} catch (error: any) {
onError(error)
console.error(error)
}
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp