Skip to content

Commit 40e6111

Browse files
committed
🔧[#42] add CSP setting help texts
1 parent 802cb98 commit 40e6111

File tree

1 file changed

+44
-5
lines changed

1 file changed

+44
-5
lines changed

open_api_framework/conf/base.py

+44-5
Original file line numberDiff line numberDiff line change
@@ -950,25 +950,64 @@ def init_sentry(before_send: Callable | None = None):
950950
# ideally we'd use BASE_URI but it'd have to be lazy or cause issues
951951
CSP_DEFAULT_SRC = [
952952
"'self'",
953-
] + config("CSP_EXTRA_DEFAULT_SRC", default=[], split=True)
953+
] + config(
954+
"CSP_EXTRA_DEFAULT_SRC",
955+
default=[],
956+
split=True,
957+
group="Content Security Policy",
958+
help_text="Extra default source URLs for CSP other than ``self``. "
959+
"Used for ``img-src``, ``style-src`` and ``script-src``",
960+
)
954961

955-
CSP_REPORT_PERCENTAGE = config("CSP_REPORT_PERCENTAGE", 1.0) # float between 0 and 1
962+
963+
CSP_REPORT_URI = config(
964+
"CSP_REPORT_URI",
965+
None,
966+
group="Content Security Policy",
967+
help_text="URI of the``report-uri`` directive.",
968+
)
969+
CSP_REPORT_PERCENTAGE = config(
970+
"CSP_REPORT_PERCENTAGE",
971+
0,
972+
group="Content Security Policy",
973+
help_text="Percentage of requests that get the ``report-uri`` directive.",
974+
) # float between 0 and 1
956975

957976
CSP_FORM_ACTION = (
958977
config(
959978
"CSP_FORM_ACTION",
960979
default=["\"'self'\""]
961-
+ config("CSP_EXTRA_FORM_ACTION", default=[], split=True),
980+
+ config(
981+
"CSP_EXTRA_FORM_ACTION",
982+
default=[],
983+
split=True,
984+
group="Content Security Policy",
985+
help_text="Add additional ``form-action`` source to the default ",
986+
),
962987
split=True,
988+
group="Content Security Policy",
989+
help_text="Override the default ``form-action`` source",
963990
)
964991
+ CORS_ALLOWED_ORIGINS
965992
)
966993

967-
CSP_IMG_SRC = CSP_DEFAULT_SRC + config("CSP_EXTRA_IMG_SRC", default=[], split=True)
994+
CSP_IMG_SRC = CSP_DEFAULT_SRC + config(
995+
"CSP_EXTRA_IMG_SRC",
996+
default=[],
997+
split=True,
998+
group="Content Security Policy",
999+
help_text="Extra ``img-src`` sources for CSP other than ``CSP_DEFAULT_SRC``.",
1000+
)
9681001

9691002
# affects <object> and <embed> tags, block everything by default but allow deploy-time
9701003
# overrides.
971-
CSP_OBJECT_SRC = config("CSP_OBJECT_SRC", default=["\"'none'\""], split=True)
1004+
CSP_OBJECT_SRC = config(
1005+
"CSP_OBJECT_SRC",
1006+
default=["\"'none'\""],
1007+
split=True,
1008+
group="Content Security Policy",
1009+
help_text="``object-src`` urls",
1010+
)
9721011

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

0 commit comments

Comments
 (0)