Skip to content
Merged
Changes from all 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
17 changes: 9 additions & 8 deletions web/packages/teleterm/csp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,22 @@ export function getConnectCsp(development: boolean) {
? 'https://kcwm2is93l.execute-api.us-west-2.amazonaws.com/prod'
: 'https://usage.teleport.dev';

let csp = `
const scriptEval = development
? // Required to make source maps work in dev mode.
"'unsafe-eval' 'unsafe-inline'"
: // Enables WASM initialization with a safer alternative to 'unsafe-eval'.
// This source expression applies specifically to WASM.
"'wasm-unsafe-eval'";

return `
default-src 'self';
connect-src 'self' ${feedbackAddress};
style-src 'self' 'unsafe-inline';
img-src 'self' data: blob:;
object-src 'none';
font-src 'self' data:;
script-src 'self' ${scriptEval};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need 'self' though in the packaged app?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I was going off the fact that it wasn't previously present, but in that scenario I believe it was covered by default-src 'self'. I wonder if it's needed though since technically we read the script from the disk in the packaged app, no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's needed, the renderer assets won't load without it:
index.html:1 Refused to load the script 'file:///Volumes/Teleport%20Connect%201.0.0-dev-arm64/Teleport%20Connect.app/Contents/Resources/app.asar/build/app/renderer/assets/index-p_BQNgK4.js' because it violates the following Content Security Policy directive: "script-src 'wasm-unsafe-eval'". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.

I believe default-src 'self' doesn't work when we explicitly set script-src.

`
.replaceAll('\n', ' ')
.trim();

if (development) {
// Required to make source maps work in dev mode.
csp += " script-src 'self' 'unsafe-eval' 'unsafe-inline';";
}

return csp;
}
Loading