File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed
Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change 77 < meta name ="viewport " content ="width=device-width,initial-scale=1.0 ">
88 <!-- Verify with https://csp-evaluator.withgoogle.com/ -->
99 <!-- TODO: fix CSP (should depend on prod/dev mode, as pre-vite )-->
10- < meta http-equiv ="Content-Security-Policy " content ="default-src 'self' *:5666 ws://*:27180 https://api.github.com/repos/ActivityWatch/activitywatch/releases/latest; img-src 'self' data:; font-src 'self' data:; style-src 'self' 'unsafe-inline'; object-src 'none'; script-src 'self' 'unsafe-eval' ">
10+ < meta http-equiv ="Content-Security-Policy " content ="default-src 'self' <%= htmlWebpackPlugin.options.templateParameters.cspDefaultSrc %> https://api.github.com/repos/ActivityWatch/activitywatch/releases/latest; img-src 'self' data:; font-src 'self' data:; style-src 'self' 'unsafe-inline'; object-src 'none'; script-src 'self' 'unsafe-eval' ">
1111 </ head >
1212 < body >
1313 < noscript >
Original file line number Diff line number Diff line change @@ -4,16 +4,35 @@ import vue from '@vitejs/plugin-vue2';
44
55export default defineConfig ( ( { mode } ) => {
66 const PRODUCTION = mode === 'production' ;
7+ const CSP = PRODUCTION ? '' : '*:5600 *:5666 ws://*:27180' ;
78
9+ // Sets the CSP
10+ const setCsp = ( ) => {
11+ return {
12+ name : 'html-transform' ,
13+ transformIndexHtml ( html ) {
14+ const pattern = '<%= htmlWebpackPlugin.options.templateParameters.cspDefaultSrc %>' ;
15+ // check if the pattern exists in the html, if not, throw error
16+ if ( ! html . includes ( pattern ) ) {
17+ throw new Error ( `Could not find pattern ${ pattern } in the html file` ) ;
18+ }
19+ return html . replace ( pattern , CSP ) ;
20+ } ,
21+ } ;
22+ } ;
23+
24+ // Return the configuration
825 return {
26+ plugins : [ setCsp ( ) , vue ( ) ] ,
927 server : {
1028 port : 27180 ,
11- // This breaks a bunch of style-related stuff (at least):
29+ // TODO: Fix this.
30+ // Breaks a bunch of style-related stuff etc.
31+ // We'd need to move in the entire CSP config in here (not just the default-src) if we want to use this.
1232 //headers: {
1333 // 'Content-Security-Policy': PRODUCTION ? "default-src 'self'" : "default-src 'self' *:5666",
1434 //},
1535 } ,
16- plugins : [ vue ( ) ] ,
1736 publicDir : './static' ,
1837 resolve : {
1938 alias : { '~' : path . resolve ( __dirname , 'src' ) } ,
You can’t perform that action at this time.
0 commit comments