Skip to content

Commit

Permalink
feat: Enhance CSP in webpack.config.js for stricter security polici…
Browse files Browse the repository at this point in the history
…es (#78)

- **Changes**:
  - Refined the `CspHtmlWebpackPlugin` configuration:
    - Added `base-uri` directive with `'self'`.
    - Updated `script-src` to include `'strict-dynamic'` and `'unsafe-inline'` for better compatibility with dynamic scripts.
    - Enabled `'unsafe-inline'` for `style-src` to accommodate inline styles.
    - Explicitly disabled `object-src` with `'none'`.
    - Added `require-trusted-types-for` to enforce Trusted Types for scripts.
  - Commented out `StrictCspHtmlWebpackPlugin` for potential future use with `enableTrustedTypes`.

- **Purpose**:
  - Strengthen security by enhancing Content Security Policy (CSP) directives.

- **Impact**:
  - Reduces vulnerabilities to XSS and related attacks while allowing necessary script and style flexibility.
  • Loading branch information
warnyul authored Dec 8, 2024
1 parent 8473e9b commit ae39d75
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,17 @@ module.exports = {
}),
new HtmlNewLineRemoverPlugin(),
new CspHtmlWebpackPlugin(
{
'default-src': "'self'",
'script-src': ["'self'", "https://www.googletagmanager.com"],
'style-src': ["'self'"],
'img-src': ["'self'"],
'font-src': ["'self'"],
'connect-src': ["'self'", "https://*.google-analytics.com", "https://firebase.googleapis.com", "https://firebaseinstallations.googleapis.com"],
},
{
'base-uri': "'self'",
'default-src': "'self'",
'script-src': ["'strict-dynamic'", 'https://www.googletagmanager.com', "'unsafe-inline'"],
'style-src': ["'unsafe-inline'"],
'img-src': ["'self'"],
'font-src': ["'self'"],
'connect-src': ["'self'", 'https://*.google-analytics.com', 'https://firebase.googleapis.com', 'https://firebaseinstallations.googleapis.com'],
'object-src': "'none'",
'require-trusted-types-for': "'script'",
},
{
hashingMethod: 'sha256',
enabled: true,
Expand Down

0 comments on commit ae39d75

Please sign in to comment.