Skip to content

Commit 5e2c7a4

Browse files
authored
Merge pull request #56 from maykinmedia/issue/42-headers-for-CSP-and-HSTS
🔧[#42] add CSP setting help texts
2 parents f29580a + 40e6111 commit 5e2c7a4

File tree

1 file changed

+44
-5
lines changed

1 file changed

+44
-5
lines changed

open_api_framework/conf/base.py

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -957,25 +957,64 @@ def init_sentry(before_send: Callable | None = None):
957957
# ideally we'd use BASE_URI but it'd have to be lazy or cause issues
958958
CSP_DEFAULT_SRC = [
959959
"'self'",
960-
] + config("CSP_EXTRA_DEFAULT_SRC", default=[], split=True)
960+
] + config(
961+
"CSP_EXTRA_DEFAULT_SRC",
962+
default=[],
963+
split=True,
964+
group="Content Security Policy",
965+
help_text="Extra default source URLs for CSP other than ``self``. "
966+
"Used for ``img-src``, ``style-src`` and ``script-src``",
967+
)
961968

962-
CSP_REPORT_PERCENTAGE = config("CSP_REPORT_PERCENTAGE", 1.0) # float between 0 and 1
969+
970+
CSP_REPORT_URI = config(
971+
"CSP_REPORT_URI",
972+
None,
973+
group="Content Security Policy",
974+
help_text="URI of the``report-uri`` directive.",
975+
)
976+
CSP_REPORT_PERCENTAGE = config(
977+
"CSP_REPORT_PERCENTAGE",
978+
0,
979+
group="Content Security Policy",
980+
help_text="Percentage of requests that get the ``report-uri`` directive.",
981+
) # float between 0 and 1
963982

964983
CSP_FORM_ACTION = (
965984
config(
966985
"CSP_FORM_ACTION",
967986
default=["\"'self'\""]
968-
+ config("CSP_EXTRA_FORM_ACTION", default=[], split=True),
987+
+ config(
988+
"CSP_EXTRA_FORM_ACTION",
989+
default=[],
990+
split=True,
991+
group="Content Security Policy",
992+
help_text="Add additional ``form-action`` source to the default ",
993+
),
969994
split=True,
995+
group="Content Security Policy",
996+
help_text="Override the default ``form-action`` source",
970997
)
971998
+ CORS_ALLOWED_ORIGINS
972999
)
9731000

974-
CSP_IMG_SRC = CSP_DEFAULT_SRC + config("CSP_EXTRA_IMG_SRC", default=[], split=True)
1001+
CSP_IMG_SRC = CSP_DEFAULT_SRC + config(
1002+
"CSP_EXTRA_IMG_SRC",
1003+
default=[],
1004+
split=True,
1005+
group="Content Security Policy",
1006+
help_text="Extra ``img-src`` sources for CSP other than ``CSP_DEFAULT_SRC``.",
1007+
)
9751008

9761009
# affects <object> and <embed> tags, block everything by default but allow deploy-time
9771010
# overrides.
978-
CSP_OBJECT_SRC = config("CSP_OBJECT_SRC", default=["\"'none'\""], split=True)
1011+
CSP_OBJECT_SRC = config(
1012+
"CSP_OBJECT_SRC",
1013+
default=["\"'none'\""],
1014+
split=True,
1015+
group="Content Security Policy",
1016+
help_text="``object-src`` urls",
1017+
)
9791018

9801019
# we must include this explicitly, otherwise the style-src only includes the nonce because
9811020
# of CSP_INCLUDE_NONCE_IN

0 commit comments

Comments
 (0)