Skip to content

Commit 69f336a

Browse files
committed
Switch to protocol-level Content-Security-Policy for most windows
The header is stronger than the tag. Ensures extension documentation pages get a CSP.
1 parent babb988 commit 69f336a

File tree

7 files changed

+27
-20
lines changed

7 files changed

+27
-20
lines changed

src-main/protocols.js

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ const packageJSON = require('../package.json');
88
/**
99
* @typedef Metadata
1010
* @property {string} root
11-
* @property {boolean} [standard]
12-
* @property {boolean} [supportFetch]
13-
* @property {boolean} [secure]
14-
* @property {boolean} [brotli]
15-
* @property {boolean} [embeddable]
16-
* @property {boolean} [stream]
17-
* @property {string} [index]
11+
* @property {boolean} [standard] Defaults to false
12+
* @property {boolean} [supportFetch] Defaults to false
13+
* @property {boolean} [secure] Defaults to false
14+
* @property {boolean} [brotli] Defaults to false
15+
* @property {boolean} [embeddable] Defaults to false
16+
* @property {boolean} [stream] Defaults to false
17+
* @property {string} [index] Defaults to none
18+
* @property {string} [csp] Defaults to none
1819
*/
1920

2021
/** @type {Record<string, Metadata>} */
@@ -27,13 +28,16 @@ const FILE_SCHEMES = {
2728
embeddable: true, // migration helper
2829
},
2930
'tw-desktop-settings': {
30-
root: path.resolve(__dirname, '../src-renderer/desktop-settings')
31+
root: path.resolve(__dirname, '../src-renderer/desktop-settings'),
32+
csp: "default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline'"
3133
},
3234
'tw-privacy': {
33-
root: path.resolve(__dirname, '../src-renderer/privacy')
35+
root: path.resolve(__dirname, '../src-renderer/privacy'),
36+
csp: "default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline'"
3437
},
3538
'tw-about': {
36-
root: path.resolve(__dirname, '../src-renderer/about')
39+
root: path.resolve(__dirname, '../src-renderer/about'),
40+
csp: "default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline'"
3741
},
3842
'tw-packager': {
3943
root: path.resolve(__dirname, '../src-renderer/packager'),
@@ -44,23 +48,28 @@ const FILE_SCHEMES = {
4448
'tw-library': {
4549
root: path.resolve(__dirname, '../dist-library-files'),
4650
supportFetch: true,
47-
brotli: true
51+
brotli: true,
52+
csp: "default-src 'none';"
4853
},
4954
'tw-extensions': {
5055
root: path.resolve(__dirname, '../dist-extensions'),
5156
supportFetch: true,
5257
embeddable: true,
5358
stream: true,
54-
index: '.html'
59+
index: '.html',
60+
csp: "default-src 'none'; img-src 'self' data:; style-src 'unsafe-inline'; script-src 'self' 'unsafe-inline'"
5561
},
5662
'tw-update': {
5763
root: path.resolve(__dirname, '../src-renderer/update'),
64+
csp: "default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline'; connect-src https://desktop.turbowarp.org"
5865
},
5966
'tw-security-prompt': {
6067
root: path.resolve(__dirname, '../src-renderer/security-prompt'),
68+
csp: "default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline';"
6169
},
6270
'tw-file-access': {
6371
root: path.resolve(__dirname, '../src-renderer/file-access'),
72+
csp: "default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline'"
6473
}
6574
};
6675

@@ -159,11 +168,15 @@ const errorPageHeaders = {
159168
*/
160169
const getBaseProtocolHeaders = metadata => {
161170
const result = {
162-
// Make sure the browser always trusts our content-type
163-
// (probably does not do anything here)
171+
// Make sure Chromium always trusts our content-type and doesn't try anything clever
164172
'x-content-type-options': 'nosniff'
165173
};
166174

175+
// Optional Content-Security-Policy
176+
if (metadata.csp) {
177+
result['content-security-policy'] = metadata.csp;
178+
}
179+
167180
// Don't allow things like extensiosn to embed custom protocols
168181
if (!metadata.embeddable) {
169182
result['x-frame-options'] = 'DENY';

src-renderer/about/about.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<html lang="en">
33
<head>
44
<meta charset="utf-8">
5-
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline'">
65
<style>
76
body {
87
margin: 0;

src-renderer/desktop-settings/desktop-settings.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<html>
33
<head>
44
<meta charset="utf-8">
5-
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline'">
65
<style>
76
body {
87
margin: 0;

src-renderer/file-access/file-access.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<html>
33
<head>
44
<meta charset="utf-8">
5-
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline'">
65
<style>
76
body {
87
margin: 0;

src-renderer/privacy/privacy.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<html lang="en">
33
<head>
44
<meta charset="utf-8">
5-
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline';">
65
<style>
76
body {
87
margin: 0;

src-renderer/security-prompt/security-prompt.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<html>
33
<head>
44
<meta charset="utf-8">
5-
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline';">
65
<style>
76
:root {
87
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;

src-renderer/update/update.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<html>
33
<head>
44
<meta charset="utf-8">
5-
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline'; connect-src https://desktop.turbowarp.org">
65
<style>
76
body {
87
margin: 0;

0 commit comments

Comments
 (0)