Skip to content
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

security: fix for major vulnerabilities #45

Merged
merged 6 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
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
74 changes: 60 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,62 @@ const rootDir = new URL('.', import.meta.url).pathname
export default defineConfig({
integrations: [
shield({
// Enables SRI hashes generation for statically generated pages
enableStatic_SRI: true, // true by default

// Enables a middleware that generates SRI hashes for dynamically
// generated pages
enableMiddleware_SRI: false, // false by default

// This is the path where we'll generate the module containing the SRI
// hashes for your scripts and styles. There's no need to pass this
// parameter if you don't need this data, but it can be useful to
// configure your CSP policies.
sriHashesModule: resolve(rootDir, 'src', 'utils', 'sriHashes.mjs'),
sri: {
// Enables SRI hashes generation for statically generated pages
enableStatic: true, // true by default

// Enables a middleware that generates SRI hashes for dynamically
// generated pages
enableMiddleware: false, // false by default

// This is the path where we'll generate the module containing the SRI
// hashes for your scripts and styles. There's no need to pass this
// parameter if you don't need this data, but it can be useful to
// configure your CSP policies.
hashesModule: resolve(rootDir, 'src', 'utils', 'sriHashes.mjs'),

// For SSR content, Cross-Origin scripts must be explicitly allow-listed
// by URL in order to be allowed by the Content Security Policy.
//
// Defaults to []
scriptsAllowListUrls: [
'https://code.jquery.com/jquery-3.7.1.slim.min.js',
],

// For SSR content, Cross-Origin styles must be explicitly allow-listed
// by URL in order to be allowed by the Content Security Policy.
//
// Defaults to []
stylesAllowListUrls: [
'https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css',
],

/**
* Inline styles are usually considered unsafe because they could make it
* easier for an attacker to inject CSS rules in dynamic pages. However, they
* don't pose a serious security risk for _most_ static pages.
*
* You can disable this option in case you want to enforce a stricter policy.
*
* @type {'all' | 'static' | false}
*
* Defaults to 'all'.
*/
allowInlineStyles: 'all',

/**
* Inline scripts are usually considered unsafe because they could make it
* easier for an attacker to inject JS code in dynamic pages. However, they
* don't pose a serious security risk for _most_ static pages.
*
* You can disable this option in case you want to enforce a stricter policy.
*
* @type {'all' | 'static' | false}
*
* Defaults to 'all'.
*/
allowInlineScript: 'all',
},

// - If set, it controls how the security headers will be generated in the
// middleware.
Expand Down Expand Up @@ -100,8 +144,10 @@ the `cspDirectives` option.

> [!IMPORTANT]
> It is advisable to set the option `sriHashesModule` in case your dynamic pages
> include static JS or CSS resources (also: do not explicitly disable the
> `enableStatic_SRI` option if you want support for those static assets).
> include static JS or CSS resources.
>
> Also, do not explicitly disable the `enableStatic_SRI` option if you want
> support for those static assets).

### Accessing metadata generated at build time

Expand Down
2 changes: 1 addition & 1 deletion e2e/fixtures/dynamic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"license": "MIT",
"dependencies": {
"@astrojs/node": "^8.2.5",
"astro": "^4.5.9"
"astro": "^4.5.10"
},
"devDependencies": {
"@kindspells/astro-shield": "link:../../.."
Expand Down
Loading
Loading