Skip to content

Commit

Permalink
Fix more issues related to CSP and Vite
Browse files Browse the repository at this point in the history
  • Loading branch information
chandra-tacc committed Jul 12, 2023
1 parent 9527992 commit db8bc6b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
18 changes: 18 additions & 0 deletions client/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,24 @@ export default defineConfig({
plugins: [
{...eslint({include: 'src/**/*.+(js|jsx|ts|tsx)', fix: false}), enforce: 'pre', },
react(),
{
name: "html-inject-nonce-into-script-tag",
enforce: "post",
transformIndexHtml(html: string) {
const regex = /<script(.*?)/gi;
const replacement = '<script nonce="{{ CSP_NONCE }}"$1';
return html.replace(regex, replacement);
},
},
{
name: "html-inject-nonce-into-link-tag",
enforce: "post",
transformIndexHtml(html: string) {
const regex = /<link(.*?)/gi;
const replacement = '<link nonce="{{ CSP_NONCE }}"$1';
return html.replace(regex, replacement);
},
},
],

resolve: {
Expand Down
6 changes: 6 additions & 0 deletions server/portal/settings/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,12 +713,15 @@
"""
CSP_CONNECT_SRC = [
"'self'",
"ws:",
"wss:",
"*.google-analytics.com",
"*.googletagmanager.com"
]
CSP_DEFAULT_SRC = ["'none'"]
CSP_FONT_SRC = [
"'self'",
"data:",
"*.bootstrapcdn.com",
"cdnjs.cloudflare.com",
"*.googleapis.com",
Expand All @@ -745,6 +748,9 @@

CSP_INCLUDE_NONCE_IN = ['script-src', 'style-src']

# By default report only until all issues are resolved
CSP_REPORT_ONLY = True

"""
SETTINGS: LOCAL OVERRIDES
"""
Expand Down
2 changes: 1 addition & 1 deletion server/portal/settings/settings_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# DJANGO SETTINGS COMMON
########################

_DEBUG = False
_DEBUG = True

# Namespace for portal
_PORTAL_NAMESPACE = 'CEP'
Expand Down

0 comments on commit db8bc6b

Please sign in to comment.