djcheckup 0.3.0__tar.gz → 0.4.0__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: djcheckup
3
- Version: 0.3.0
3
+ Version: 0.4.0
4
4
  Summary: DJ Checkup is a security scanner for Django sites.
5
5
  Author: Stuart Maxwell
6
6
  Author-email: Stuart Maxwell <stuart@amanzi.nz>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "djcheckup"
3
- version = "0.3.0"
3
+ version = "0.4.0"
4
4
  description = "DJ Checkup is a security scanner for Django sites."
5
5
  readme = "README.md"
6
6
  authors = [{ name = "Stuart Maxwell", email = "stuart@amanzi.nz" }]
@@ -75,12 +75,13 @@ Reference:
75
75
  csrf_samesite_check = CookieSameSiteCheck(
76
76
  check_id="csrf_samesite_check",
77
77
  depends_on="csrf_check",
78
- name="Is the CSRF cookie SameSite=Lax?",
78
+ name="Does the CSRF cookie have a SameSite flag?",
79
79
  cookie_name="csrftoken",
80
- samesite_value="Lax",
81
80
  success=True,
82
81
  severity=SeverityWeight.HIGH,
83
- success_message="CSRF cookie is marked as SameSite=Lax, which helps prevent CSRF attacks via cross-site requests.",
82
+ success_message="""
83
+ CSRF cookie is marked as SameSite=Lax or SameSite=Strict, which helps prevent CSRF attacks via cross-site requests.
84
+ """,
84
85
  failure_message="""
85
86
  Your CSRF cookie is not marked as SameSite=Lax. This increases the risk of CSRF attacks.
86
87
  Set `CSRF_COOKIE_SAMESITE = 'Lax'` in your Django settings.
@@ -263,12 +264,11 @@ Reference:
263
264
  sessionid_samesite_check = CookieSameSiteCheck(
264
265
  check_id="sessionid_samesite_check",
265
266
  depends_on="sessionid_cookie_check",
266
- name="Is the sessionid cookie SameSite=Lax?",
267
+ name="Does the sessionid cookie have a SameSite flag?",
267
268
  cookie_name="sessionid",
268
- samesite_value="Lax",
269
269
  success=True,
270
270
  severity=SeverityWeight.HIGH,
271
- success_message="Sessionid cookie is marked as SameSite=Lax. This helps prevent CSRF attacks.",
271
+ success_message="Sessionid cookie is marked as SameSite=Lax or SameSite=Strict. This helps prevent CSRF attacks.",
272
272
  failure_message="""
273
273
  Your sessionid cookie is not marked as SameSite=Lax. This increases the risk of CSRF attacks.
274
274
  Set `SESSION_COOKIE_SAMESITE = 'Lax'` in your Django settings.
@@ -174,10 +174,14 @@ class CookieHttpOnlyCheck(_BaseCheck):
174
174
 
175
175
  @dataclass
176
176
  class CookieSameSiteCheck(_BaseCheck):
177
- """A cookie SameSite check."""
177
+ """A cookie SameSite check.
178
+
179
+ Checks that the cookie has the expected SameSite value.
180
+ If the `samesite_value` is omitted, then it checks if the value is set to Lax or Strict.
181
+ """
178
182
 
179
183
  cookie_name: str
180
- samesite_value: Literal["Strict", "Lax", "None"]
184
+ samesite_value: Literal["Strict", "Lax", "None"] | None = None
181
185
 
182
186
  def check(self, context: SiteCheckContext) -> bool:
183
187
  """Check if a specific cookie has a SameSite attribute."""
@@ -186,6 +190,9 @@ class CookieSameSiteCheck(_BaseCheck):
186
190
 
187
191
  for cookie in context.cookies:
188
192
  if cookie.name == self.cookie_name:
193
+ if not self.samesite_value:
194
+ return cookie.get_nonstandard_attr("SameSite") in ["Lax", "Strict"]
195
+
189
196
  return cookie.get_nonstandard_attr("SameSite") == self.samesite_value
190
197
 
191
198
  return False
File without changes
File without changes