open-api-framework 0.7.1__tar.gz → 0.8.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. {open_api_framework-0.7.1 → open_api_framework-0.8.1}/CHANGELOG.rst +29 -0
  2. {open_api_framework-0.7.1/open_api_framework.egg-info → open_api_framework-0.8.1}/PKG-INFO +4 -3
  3. {open_api_framework-0.7.1 → open_api_framework-0.8.1}/README.rst +1 -1
  4. {open_api_framework-0.7.1 → open_api_framework-0.8.1}/open_api_framework/conf/base.py +120 -11
  5. {open_api_framework-0.7.1 → open_api_framework-0.8.1}/open_api_framework/templates/open_api_framework/env_config.rst +1 -1
  6. {open_api_framework-0.7.1 → open_api_framework-0.8.1/open_api_framework.egg-info}/PKG-INFO +4 -3
  7. {open_api_framework-0.7.1 → open_api_framework-0.8.1}/open_api_framework.egg-info/requires.txt +2 -1
  8. {open_api_framework-0.7.1 → open_api_framework-0.8.1}/pyproject.toml +4 -3
  9. {open_api_framework-0.7.1 → open_api_framework-0.8.1}/LICENSE +0 -0
  10. {open_api_framework-0.7.1 → open_api_framework-0.8.1}/MANIFEST.in +0 -0
  11. {open_api_framework-0.7.1 → open_api_framework-0.8.1}/open_api_framework/__init__.py +0 -0
  12. {open_api_framework-0.7.1 → open_api_framework-0.8.1}/open_api_framework/apps.py +0 -0
  13. {open_api_framework-0.7.1 → open_api_framework-0.8.1}/open_api_framework/conf/__init__.py +0 -0
  14. {open_api_framework-0.7.1 → open_api_framework-0.8.1}/open_api_framework/conf/utils.py +0 -0
  15. {open_api_framework-0.7.1 → open_api_framework-0.8.1}/open_api_framework/context_processors.py +0 -0
  16. {open_api_framework-0.7.1 → open_api_framework-0.8.1}/open_api_framework/management/__init__.py +0 -0
  17. {open_api_framework-0.7.1 → open_api_framework-0.8.1}/open_api_framework/management/commands/__init__.py +0 -0
  18. {open_api_framework-0.7.1 → open_api_framework-0.8.1}/open_api_framework/management/commands/generate_envvar_docs.py +0 -0
  19. {open_api_framework-0.7.1 → open_api_framework-0.8.1}/open_api_framework/py.typed +0 -0
  20. {open_api_framework-0.7.1 → open_api_framework-0.8.1}/open_api_framework/static/open_api_framework/css/admin.css +0 -0
  21. {open_api_framework-0.7.1 → open_api_framework-0.8.1}/open_api_framework/templates/open_api_framework/admin/base_site.html +0 -0
  22. {open_api_framework-0.7.1 → open_api_framework-0.8.1}/open_api_framework/templates/open_api_framework/components/environment.html +0 -0
  23. {open_api_framework-0.7.1 → open_api_framework-0.8.1}/open_api_framework/templates/open_api_framework/components/version.html +0 -0
  24. {open_api_framework-0.7.1 → open_api_framework-0.8.1}/open_api_framework/templatetags/__init__.py +0 -0
  25. {open_api_framework-0.7.1 → open_api_framework-0.8.1}/open_api_framework/templatetags/doc_tags.py +0 -0
  26. {open_api_framework-0.7.1 → open_api_framework-0.8.1}/open_api_framework/templatetags/open_api_framework.py +0 -0
  27. {open_api_framework-0.7.1 → open_api_framework-0.8.1}/open_api_framework.egg-info/SOURCES.txt +0 -0
  28. {open_api_framework-0.7.1 → open_api_framework-0.8.1}/open_api_framework.egg-info/dependency_links.txt +0 -0
  29. {open_api_framework-0.7.1 → open_api_framework-0.8.1}/open_api_framework.egg-info/top_level.txt +0 -0
  30. {open_api_framework-0.7.1 → open_api_framework-0.8.1}/setup.cfg +0 -0
  31. {open_api_framework-0.7.1 → open_api_framework-0.8.1}/tests/test_config_helpers.py +0 -0
  32. {open_api_framework-0.7.1 → open_api_framework-0.8.1}/tests/test_generate_envvar_docs.py +0 -0
@@ -1,6 +1,35 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ 0.8.1 (2024-09-26)
5
+ ------------------
6
+
7
+ **Bugfixes/QOL**
8
+
9
+ * Change SESSION_COOKIE_SAMESITE to "Lax" to fix OIDC (#72)
10
+ * Remove url from SECRET_KEY help text (#76)
11
+ * Change CSP headers to support API schema page
12
+
13
+ 0.8.0 (2024-08-22)
14
+ ------------------
15
+
16
+ **New features**
17
+
18
+ * Add Django CSP with configurable settings
19
+ * Add SECURE_HSTS_SECONDS and CSRF_COOKIE_HTTPONLY settings
20
+
21
+ .. warning::
22
+
23
+ SECURE_HSTS_SECONDS has been added with a default of 31536000 seconds, ensure that
24
+ before upgrading to this version of open-api-framework, your entire application is served
25
+ over HTTPS, otherwise this setting can break parts of your application (see https://docs.djangoproject.com/en/4.2/ref/middleware/#http-strict-transport-security)
26
+
27
+ **Bugfixes/QOL**
28
+
29
+ * Fix rendering for envvar defaults (previously quotes were escaped)
30
+ * Move ``CACHE_DEFAULT``, ``CACHE_AXES``, ``EMAIL_HOST`` envvars to Required group (because they are required for Docker)
31
+ * Add CI job to check if all envvars are either documented or excluded from documentation
32
+
4
33
  0.7.1 (2024-08-16)
5
34
  ------------------
6
35
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: open_api_framework
3
- Version: 0.7.1
3
+ Version: 0.8.1
4
4
  Summary: A metapackage for registration components, that bundles the dependencies shared between these components and provides generic settings
5
5
  Author-email: Maykin Media <support@maykinmedia.nl>
6
6
  License: Copyright © Maykin 2024
@@ -41,7 +41,8 @@ Requires-Dist: django-redis>=5.4.0
41
41
  Requires-Dist: djangorestframework>=3.15.2
42
42
  Requires-Dist: djangorestframework-gis>=1.0
43
43
  Requires-Dist: django-filter>=24.2
44
- Requires-Dist: drf-spectacular>=0.27.2
44
+ Requires-Dist: drf-spectacular[sidecar]>=0.27.2
45
+ Requires-Dist: django-csp>=3.8
45
46
  Requires-Dist: djangorestframework-inclusions>=1.2.0
46
47
  Requires-Dist: commonground-api-common>=1.12.1
47
48
  Requires-Dist: mozilla-django-oidc-db>=0.19.0
@@ -77,7 +78,7 @@ Requires-Dist: twine; extra == "release"
77
78
  Open API Framework
78
79
  ==================
79
80
 
80
- :Version: 0.7.1
81
+ :Version: 0.8.1
81
82
  :Source: https://github.com/maykinmedia/open-api-framework
82
83
  :Keywords: metapackage, dependencies
83
84
 
@@ -1,7 +1,7 @@
1
1
  Open API Framework
2
2
  ==================
3
3
 
4
- :Version: 0.7.1
4
+ :Version: 0.8.1
5
5
  :Source: https://github.com/maykinmedia/open-api-framework
6
6
  :Keywords: metapackage, dependencies
7
7
 
@@ -39,10 +39,7 @@ SITE_ID = config(
39
39
  # SECURITY WARNING: keep the secret key used in production secret!
40
40
  SECRET_KEY = config(
41
41
  "SECRET_KEY",
42
- help_text=(
43
- "Secret key that's used for certain cryptographic utilities. "
44
- "You should generate one via `miniwebtool <https://www.miniwebtool.com/django-secret-key-generator>`_"
45
- ),
42
+ help_text="Secret key that's used for certain cryptographic utilities. ",
46
43
  )
47
44
 
48
45
  # NEVER run with DEBUG=True in production-like environments
@@ -149,12 +146,17 @@ DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
149
146
  CACHE_DEFAULT = config(
150
147
  "CACHE_DEFAULT",
151
148
  "localhost:6379/0",
152
- help_text="redis cache address for the default cache",
149
+ help_text="redis cache address for the default cache (this **MUST** be set when using Docker)",
150
+ group="Required",
153
151
  )
154
152
  CACHE_AXES = config(
155
153
  "CACHE_AXES",
156
154
  "localhost:6379/0",
157
- help_text="redis cache address for the brute force login protection cache",
155
+ help_text=(
156
+ "redis cache address for the brute force login protection cache "
157
+ "(this **MUST** be set when using Docker)"
158
+ ),
159
+ group="Required",
158
160
  )
159
161
 
160
162
  CACHES = {
@@ -203,10 +205,12 @@ INSTALLED_APPS = [
203
205
  # External applications.
204
206
  "axes",
205
207
  "django_filters",
208
+ "csp",
206
209
  "corsheaders",
207
210
  "vng_api_common",
208
211
  "notifications_api_common",
209
212
  "drf_spectacular",
213
+ "drf_spectacular_sidecar",
210
214
  "rest_framework",
211
215
  "django_markup",
212
216
  "solo",
@@ -241,6 +245,7 @@ MIDDLEWARE = [
241
245
  "django.contrib.messages.middleware.MessageMiddleware",
242
246
  "django.middleware.clickjacking.XFrameOptionsMiddleware",
243
247
  "axes.middleware.AxesMiddleware",
248
+ "csp.contrib.rate_limiting.RateLimitedCSPMiddleware",
244
249
  ]
245
250
 
246
251
  ROOT_URLCONF = f"{PROJECT_DIRNAME}.urls"
@@ -305,7 +310,8 @@ FILE_UPLOAD_PERMISSIONS = 0o644
305
310
  EMAIL_HOST = config(
306
311
  "EMAIL_HOST",
307
312
  default="localhost",
308
- help_text="hostname for the outgoing e-mail server",
313
+ help_text="hostname for the outgoing e-mail server (this **MUST** be set when using Docker)",
314
+ group="Required",
309
315
  )
310
316
  EMAIL_PORT = config(
311
317
  "EMAIL_PORT",
@@ -541,15 +547,17 @@ SESSION_COOKIE_SECURE = IS_HTTPS
541
547
  SESSION_COOKIE_HTTPONLY = True
542
548
  SESSION_COOKIE_SAMESITE = config(
543
549
  "SESSION_COOKIE_SAMESITE",
544
- "Strict",
550
+ "Lax",
545
551
  help_text=(
546
552
  "The value of the SameSite flag on the session cookie. This flag prevents the "
547
553
  "cookie from being sent in cross-site requests thus preventing CSRF attacks and "
548
554
  "making some methods of stealing session cookie impossible."
555
+ "Currently interferes with OIDC. Keep the value set at Lax if used."
549
556
  ),
550
557
  )
551
558
 
552
559
  CSRF_COOKIE_SECURE = IS_HTTPS
560
+ CSRF_COOKIE_HTTPONLY = True
553
561
  CSRF_COOKIE_SAMESITE = config(
554
562
  "CSRF_COOKIE_SAMESITE",
555
563
  "Strict",
@@ -559,6 +567,9 @@ CSRF_COOKIE_SAMESITE = config(
559
567
  ),
560
568
  )
561
569
 
570
+ if IS_HTTPS:
571
+ SECURE_HSTS_SECONDS = 31536000
572
+
562
573
  X_FRAME_OPTIONS = "DENY"
563
574
 
564
575
  #
@@ -606,7 +617,7 @@ if subpath:
606
617
  SUBPATH = subpath
607
618
 
608
619
  if "GIT_SHA" in os.environ:
609
- GIT_SHA = config("GIT_SHA", "")
620
+ GIT_SHA = config("GIT_SHA", "", add_to_docs=False)
610
621
  # in docker (build) context, there is no .git directory
611
622
  elif (Path(BASE_DIR) / ".git").exists():
612
623
  try:
@@ -837,7 +848,7 @@ MOZILLA_DJANGO_OIDC_DB_CACHE_TIMEOUT = 5 * 60
837
848
  ELASTIC_APM_SERVER_URL = config(
838
849
  "ELASTIC_APM_SERVER_URL",
839
850
  None,
840
- "URL where Elastic APM is hosted",
851
+ help_text="URL where Elastic APM is hosted",
841
852
  group="Elastic APM",
842
853
  )
843
854
  ELASTIC_APM = {
@@ -855,7 +866,7 @@ ELASTIC_APM = {
855
866
  "SECRET_TOKEN": config(
856
867
  "ELASTIC_APM_SECRET_TOKEN",
857
868
  "default",
858
- "Token used to communicate with Elastic APM",
869
+ help_text="Token used to communicate with Elastic APM",
859
870
  group="Elastic APM",
860
871
  ),
861
872
  "SERVER_URL": ELASTIC_APM_SERVER_URL,
@@ -932,3 +943,101 @@ LOG_OUTGOING_REQUESTS_MAX_AGE = config(
932
943
  default=7,
933
944
  help_text="The amount of time after which request logs should be deleted from the database",
934
945
  ) # number of days
946
+
947
+
948
+ #
949
+ # Django CSP settings
950
+ #
951
+ # explanation of directives: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
952
+ # and how to specify them: https://django-csp.readthedocs.io/en/latest/configuration.html
953
+ #
954
+ # NOTE: make sure values are a tuple or list, and to quote special values like 'self'
955
+
956
+ # ideally we'd use BASE_URI but it'd have to be lazy or cause issues
957
+ CSP_DEFAULT_SRC = ["'self'"] + config(
958
+ "CSP_EXTRA_DEFAULT_SRC",
959
+ default=[],
960
+ split=True,
961
+ group="Content Security Policy",
962
+ help_text="Extra default source URLs for CSP other than ``self``. "
963
+ "Used for ``img-src``, ``style-src`` and ``script-src``",
964
+ )
965
+
966
+
967
+ CSP_REPORT_URI = config(
968
+ "CSP_REPORT_URI",
969
+ None,
970
+ group="Content Security Policy",
971
+ help_text="URI of the``report-uri`` directive.",
972
+ )
973
+ CSP_REPORT_PERCENTAGE = config(
974
+ "CSP_REPORT_PERCENTAGE",
975
+ 0,
976
+ group="Content Security Policy",
977
+ help_text="Percentage of requests that get the ``report-uri`` directive.",
978
+ ) # float between 0 and 1
979
+
980
+ CSP_FORM_ACTION = (
981
+ config(
982
+ "CSP_FORM_ACTION",
983
+ default=["\"'self'\""]
984
+ + config(
985
+ "CSP_EXTRA_FORM_ACTION",
986
+ default=[],
987
+ split=True,
988
+ group="Content Security Policy",
989
+ help_text="Add additional ``form-action`` source to the default ",
990
+ ),
991
+ split=True,
992
+ group="Content Security Policy",
993
+ help_text="Override the default ``form-action`` source",
994
+ )
995
+ + CORS_ALLOWED_ORIGINS
996
+ )
997
+
998
+ CSP_IMG_SRC = (
999
+ CSP_DEFAULT_SRC
1000
+ + ["data:", "cdn.redoc.ly"] # used by DRF spectacular
1001
+ + 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
+ )
1008
+ )
1009
+
1010
+ # affects <object> and <embed> tags, block everything by default but allow deploy-time
1011
+ # overrides.
1012
+ CSP_OBJECT_SRC = config(
1013
+ "CSP_OBJECT_SRC",
1014
+ default=["\"'none'\""],
1015
+ split=True,
1016
+ group="Content Security Policy",
1017
+ help_text="``object-src`` urls",
1018
+ )
1019
+
1020
+ # we must include this explicitly, otherwise the style-src only includes the nonce because
1021
+ # of CSP_INCLUDE_NONCE_IN
1022
+ CSP_STYLE_SRC = CSP_DEFAULT_SRC + [
1023
+ "'unsafe-inline'",
1024
+ "fonts.googleapis.com",
1025
+ ] # used by DRF spectacular
1026
+ CSP_SCRIPT_SRC = CSP_DEFAULT_SRC + ["'unsafe-inline'"]
1027
+ CSP_FONT_SRC = ("'self'", "fonts.gstatic.com")
1028
+ CSP_WORKER_SRC = ("'self'", "blob:")
1029
+
1030
+ # firefox does not get the nonce from default-src, see
1031
+ # https://stackoverflow.com/a/63376012
1032
+ CSP_INCLUDE_NONCE_IN = ["style-src", "script-src"]
1033
+
1034
+ # directives that don't fallback to default-src
1035
+ CSP_BASE_URI = ["'self'"]
1036
+
1037
+ # Frame directives do not fall back to default-src
1038
+ CSP_FRAME_ANCESTORS = ["'none'"] # equivalent to X-Frame-Options: deny
1039
+ CSP_FRAME_SRC = ["'self'"]
1040
+ # CSP_NAVIGATE_TO = ["'self'"] # this will break all outgoing links etc # too much & tricky, see note on MDN
1041
+ # CSP_SANDBOX # too much
1042
+
1043
+ CSP_UPGRADE_INSECURE_REQUESTS = False # TODO enable on production?
@@ -13,7 +13,7 @@ Available environment variables
13
13
  {{group_name}}
14
14
  {{group_name|repeat_char:"-"}}
15
15
 
16
- {% for var in vars %}* ``{{var.name}}``: {% if var.help_text %}{{var.help_text|safe|ensure_endswith:"."}}{% endif %}{% if var.auto_display_default and not var.default|is_undefined %} Defaults to: ``{{var.default|to_str}}``.{% endif %}
16
+ {% for var in vars %}* ``{{var.name}}``: {% if var.help_text %}{{var.help_text|safe|ensure_endswith:"."}}{% endif %}{% if var.auto_display_default and not var.default|is_undefined %} Defaults to: ``{{var.default|to_str|safe}}``.{% endif %}
17
17
  {% endfor %}
18
18
  {% endfor %}
19
19
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: open_api_framework
3
- Version: 0.7.1
3
+ Version: 0.8.1
4
4
  Summary: A metapackage for registration components, that bundles the dependencies shared between these components and provides generic settings
5
5
  Author-email: Maykin Media <support@maykinmedia.nl>
6
6
  License: Copyright © Maykin 2024
@@ -41,7 +41,8 @@ Requires-Dist: django-redis>=5.4.0
41
41
  Requires-Dist: djangorestframework>=3.15.2
42
42
  Requires-Dist: djangorestframework-gis>=1.0
43
43
  Requires-Dist: django-filter>=24.2
44
- Requires-Dist: drf-spectacular>=0.27.2
44
+ Requires-Dist: drf-spectacular[sidecar]>=0.27.2
45
+ Requires-Dist: django-csp>=3.8
45
46
  Requires-Dist: djangorestframework-inclusions>=1.2.0
46
47
  Requires-Dist: commonground-api-common>=1.12.1
47
48
  Requires-Dist: mozilla-django-oidc-db>=0.19.0
@@ -77,7 +78,7 @@ Requires-Dist: twine; extra == "release"
77
78
  Open API Framework
78
79
  ==================
79
80
 
80
- :Version: 0.7.1
81
+ :Version: 0.8.1
81
82
  :Source: https://github.com/maykinmedia/open-api-framework
82
83
  :Keywords: metapackage, dependencies
83
84
 
@@ -9,7 +9,8 @@ django-redis>=5.4.0
9
9
  djangorestframework>=3.15.2
10
10
  djangorestframework-gis>=1.0
11
11
  django-filter>=24.2
12
- drf-spectacular>=0.27.2
12
+ drf-spectacular[sidecar]>=0.27.2
13
+ django-csp>=3.8
13
14
  djangorestframework-inclusions>=1.2.0
14
15
  commonground-api-common>=1.12.1
15
16
  mozilla-django-oidc-db>=0.19.0
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "open_api_framework"
7
- version = "0.7.1"
7
+ version = "0.8.1"
8
8
  description = "A metapackage for registration components, that bundles the dependencies shared between these components and provides generic settings"
9
9
  authors = [
10
10
  {name = "Maykin Media", email = "support@maykinmedia.nl"}
@@ -38,7 +38,8 @@ dependencies = [
38
38
  "djangorestframework>=3.15.2",
39
39
  "djangorestframework-gis>=1.0",
40
40
  "django-filter>=24.2",
41
- "drf-spectacular>=0.27.2",
41
+ "drf-spectacular[sidecar]>=0.27.2",
42
+ "django-csp>=3.8",
42
43
  "djangorestframework-inclusions>=1.2.0",
43
44
  "commonground-api-common>=1.12.1",
44
45
  "mozilla-django-oidc-db>=0.19.0",
@@ -100,7 +101,7 @@ testpaths = ["tests"]
100
101
  DJANGO_SETTINGS_MODULE = "testapp.settings"
101
102
 
102
103
  [tool.bumpversion]
103
- current_version = "0.7.1"
104
+ current_version = "0.8.1"
104
105
  files = [
105
106
  {filename = "pyproject.toml"},
106
107
  {filename = "README.rst"},