Skip to content

Feature/strict csp #80

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 41 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
253d645
Use @pota instead of pota
jesse-mm Sep 15, 2022
692635b
react templates: disable runtime chunk
jesse-mm Sep 15, 2022
72ce5ef
react template: implement CSP header in dev mode
jesse-mm Sep 16, 2022
b83309b
react template: implement CSP header in dev mode
jesse-mm Sep 16, 2022
215ec09
react template: add CSP information
jesse-mm Sep 16, 2022
106a658
react template: add ts-node as dev dependency
jesse-mm Sep 16, 2022
58ce70b
react template: add postbuild script
jesse-mm Sep 16, 2022
f61077e
react template: run postbuild script after build
jesse-mm Sep 16, 2022
b3c83aa
react-base template: add CSP information
jesse-mm Sep 16, 2022
4fdb402
react-base template: add strict CSP header implementation
jesse-mm Sep 16, 2022
08c8c7d
react-base template: add strict CSP header implementation
jesse-mm Sep 16, 2022
c9e8509
react-base template: add ts-node as dev dependency
jesse-mm Sep 16, 2022
70f3f08
react-base template: add post build script
jesse-mm Sep 16, 2022
028e0ae
react-base template: run postbuild script after build
jesse-mm Sep 16, 2022
b0bb066
Add platform and IDE files/directories to gitignore
jesse-mm Sep 16, 2022
99f2f1a
react-vite-scripts: Add vite-plugin-html for parsing/processing index…
jesse-mm Sep 16, 2022
6ce696b
react-vite-scripts: Add createHtmlPlugin to plugins
jesse-mm Sep 16, 2022
664db02
react-template: add vite compatible index
jesse-mm Sep 16, 2022
58bb7b4
react-template: process vite specific generated scripts
jesse-mm Sep 16, 2022
d68be20
react-template: add NODE_ENV=production to trigger production build f…
jesse-mm Sep 16, 2022
d6138cc
react-base-template: add vite compatible index
jesse-mm Sep 16, 2022
66f705e
react-base template: add NODE_ENV=production to trigger production bu…
jesse-mm Sep 16, 2022
00c521a
muban template: update CSP header and add documentation
jesse-mm Sep 23, 2022
0433b45
vanilla template: add CSP header and script loader
jesse-mm Sep 23, 2022
6ef06e8
vanilla template: add standard editorconfig
jesse-mm Sep 23, 2022
9a0089e
vanilla template: add vite parseable index template
jesse-mm Sep 23, 2022
0005f70
vanilla template: add postBuild script for processing CSP dependencies
jesse-mm Sep 23, 2022
8a2647f
vanilla template: render DOM elements using createElement
jesse-mm Sep 23, 2022
6f1da21
vanilla template: add postBuild script and added ts-node dep
jesse-mm Sep 23, 2022
619ffba
vanilla template: add CSP implementation details to README
jesse-mm Sep 23, 2022
f53fb0f
react-base template: add default editorconfig
jesse-mm Sep 23, 2022
b2215db
react-base template: keep csp header in build output
jesse-mm Sep 30, 2022
ac8cf6f
react-base template: execute replace on the right content
jesse-mm Sep 30, 2022
c781a38
react-base template: execute replace on the right content
jesse-mm Sep 30, 2022
b93a1e5
react template: add standard editorconfig
jesse-mm Sep 30, 2022
cd86fce
react template: update index files maintain CSP header after build
jesse-mm Sep 30, 2022
5f7ef18
react template: parse the correct template contents
jesse-mm Sep 30, 2022
59ba4eb
react template: pass env correctly to npm script build argument
jesse-mm Sep 30, 2022
da38aec
scripts: add createHtmlPlugin as core vite script dependency
jesse-mm Sep 30, 2022
1a3095e
vanilla template: reword comment automatic script injection
jesse-mm Sep 30, 2022
09445a2
templates: add vite note to README file
jesse-mm Sep 30, 2022
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
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# misc
.DS_Store
Thumbs.db

# Logs
*.log

Expand All @@ -16,3 +20,9 @@ temp/

*.tgz
tsconfig.tsbuildinfo

# IntelliJ
.idea

# VSCode
.vscode
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ npm pkg set pota="../../scripts/webpack/lib/index.js"
> Example:

```bash
npm init pota -- --template templates/vanilla
npm init @pota -- --template templates/vanilla
```

NOTE: [`@pota/create`](core/create-pota) currently does not support project creation with local scripts packages.
Expand All @@ -110,7 +110,7 @@ However, these can be easily installed after the project is created (see next se
> Example:

```bash
npm init pota -- --template templates/vanilla --no-scripts
npm init @pota -- --template templates/vanilla --no-scripts
```

## Known Issues
Expand Down
162 changes: 155 additions & 7 deletions scripts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion scripts/react-vite/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class ReactViteConfig extends ViteConfig {
...(await super.plugins()),
...viteReact({
babel: this.babelConfig,
}),
})
];
}

Expand Down
3 changes: 3 additions & 0 deletions scripts/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,8 @@
},
"peerDependencies": {
"@pota/cli": "~2.0.0"
},
"devDependencies": {
"vite-plugin-html": "^3.2.0"
}
}
12 changes: 11 additions & 1 deletion scripts/vite/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { BuildOptions, DevOptions, CommonOptions, PreviewOptions } from './

import { paths } from './paths.js';
import { injectEntryTagPlugin } from './plugins/inject-entry-tag-plugin.js';
import { createHtmlPlugin } from 'vite-plugin-html';

export type ViteConfigOptions = CommonOptions &
Partial<BuildOptions> &
Expand All @@ -26,7 +27,16 @@ export class ViteConfig<C extends ViteConfigOptions = ViteConfigOptions> {
}

public async plugins(): Promise<Array<PluginOption>> {
return [injectEntryTagPlugin(this.entry)];
return [
...createHtmlPlugin({
inject: {
data: {
isDevelopment: this.isDev,
},
}
}),
injectEntryTagPlugin(this.entry),
];
}

public async final(): Promise<UserConfig> {
Expand Down
7 changes: 7 additions & 0 deletions templates/muban/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ When adding a new dependency that requires an installation script to run make su

> Important: After running `npm install` or `npm ci` always run `npm run postinstall` afterwards before running other scripts.

### Content Security Policy ([CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP))

This application has been build with a [strict content security policy](https://csp.withgoogle.com/docs/strict-csp.html). To enforce this policy
add the following CSP header to the request response.

`Content-Security-Policy: script-src 'sha256-+OVgFCkyF2/rZ6qyfsNnIisCRI6dtMZw3w0Y4xiYagw=' 'strict-dynamic' https: 'unsafe-inline'; object-src 'none'; base-uri 'none';`

## Documentation 📄

Documentation on the `muban-template` and [`muban-webpack-scripts`](../../scripts/muban-webpack) can
Expand Down
4 changes: 2 additions & 2 deletions templates/muban/src/pages/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<meta name="app-script" content="{{publicPath}}static/chunks/main.js" />

<meta http-equiv="Content-Security-Policy" content="script-src 'sha256-+OVgFCkyF2/rZ6qyfsNnIisCRI6dtMZw3w0Y4xiYagw=' 'strict-dynamic' https: 'unsafe-inline'; object-src 'none'; base-uri 'none';">
<meta http-equiv="Content-Security-Policy" content="script-src 'sha256-yyNoIT+kJT1MVsxspvZSCNjvwqqNKH1g+O3BVXpWOvg=' 'strict-dynamic' https: 'unsafe-inline'; object-src 'none'; base-uri 'none';">

<link rel="stylesheet" href="{{publicPath}}static/css/main.css" />
</head>
Expand All @@ -24,7 +24,7 @@

<!-- @formatter:off -->
<!-- prettier-ignore -->
<script>!function(){for(var o=document.querySelectorAll('html > head > meta[name="app-script"]'),t=0;t<o.length;t++){var e=o[t].getAttribute("content"),n=document.createElement("script");n.src=e,n.src.substr(0,window.location.origin.length)!==window.location.origin?window.console&&console.error("[ScriptLoader] Cannot load "+e+"."):document.body.appendChild(n)}}()</script>
<script>!function(){for(var e=document.querySelectorAll('html > head > meta[name="app-script"]'),o=0;o<e.length;o++){var t=e[o].getAttribute("content"),n=document.createElement("script");n.src=t,n.src.substr(0,window.location.origin.length)!==window.location.origin?window.console&&console.error("[ScriptLoader] Cannot load "+t+"."):(document.body.appendChild(n),document.head.removeChild(e[o]))}}();</script>
<!-- @formatter:on -->
</body>
</html>
Loading