Skip to content

Commit ae39d75

Browse files
authored
feat: Enhance CSP in webpack.config.js for stricter security policies (#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.
1 parent 8473e9b commit ae39d75

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

webpack.config.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,17 @@ module.exports = {
202202
}),
203203
new HtmlNewLineRemoverPlugin(),
204204
new CspHtmlWebpackPlugin(
205-
{
206-
'default-src': "'self'",
207-
'script-src': ["'self'", "https://www.googletagmanager.com"],
208-
'style-src': ["'self'"],
209-
'img-src': ["'self'"],
210-
'font-src': ["'self'"],
211-
'connect-src': ["'self'", "https://*.google-analytics.com", "https://firebase.googleapis.com", "https://firebaseinstallations.googleapis.com"],
212-
},
205+
{
206+
'base-uri': "'self'",
207+
'default-src': "'self'",
208+
'script-src': ["'strict-dynamic'", 'https://www.googletagmanager.com', "'unsafe-inline'"],
209+
'style-src': ["'unsafe-inline'"],
210+
'img-src': ["'self'"],
211+
'font-src': ["'self'"],
212+
'connect-src': ["'self'", 'https://*.google-analytics.com', 'https://firebase.googleapis.com', 'https://firebaseinstallations.googleapis.com'],
213+
'object-src': "'none'",
214+
'require-trusted-types-for': "'script'",
215+
},
213216
{
214217
hashingMethod: 'sha256',
215218
enabled: true,

0 commit comments

Comments
 (0)