Skip to content

Commit 2faabec

Browse files
committed
feat(sentry): support CSP report-uri directive
sentry has out of the box support for receiving CSP reports https://docs.sentry.io/product/security-policy-reporting/
1 parent 24d954f commit 2faabec

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

benefits/sentry.py

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111

1212
SENTRY_ENVIRONMENT = os.environ.get("SENTRY_ENVIRONMENT", "local")
13+
SENTRY_CSP_REPORT_URI = None
1314

1415

1516
def git_available():
@@ -82,5 +83,9 @@ def configure():
8283
send_default_pii=False,
8384
event_scrubber=EventScrubber(denylist=get_denylist()),
8485
)
86+
87+
# override the module-level variable when configuration happens, if set
88+
global SENTRY_CSP_REPORT_URI
89+
SENTRY_CSP_REPORT_URI = os.environ.get("SENTRY_REPORT_URI", "")
8590
else:
8691
print("SENTRY_DSN not set, so won't send events")

benefits/settings.py

+3
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,9 @@ def _filter_empty(ls):
300300

301301
CSP_OBJECT_SRC = ["'none'"]
302302

303+
if sentry.SENTRY_CSP_REPORT_URI:
304+
CSP_REPORT_URI = [sentry.SENTRY_CSP_REPORT_URI]
305+
303306
CSP_SCRIPT_SRC = [
304307
"https://cdn.amplitude.com/libs/",
305308
"https://cdn.jsdelivr.net/",

terraform/app_service.tf

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ resource "azurerm_linux_web_app" "main" {
7878
# Sentry
7979
"SENTRY_DSN" = "${local.secret_prefix}sentry-dsn)",
8080
"SENTRY_ENVIRONMENT" = local.env_name,
81+
"SENTRY_REPORT_URI" = "${local.secret_prefix}sentry-report-uri)",
8182

8283
# Environment variables for data migration
8384
"MST_SENIOR_GROUP_ID" = "${local.secret_prefix}mst-senior-group-id)",

0 commit comments

Comments
 (0)