Skip to content

Commit

Permalink
fix: use instance case
Browse files Browse the repository at this point in the history
  • Loading branch information
elsapet committed May 16, 2024
1 parent fd21b28 commit b2bea82
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
23 changes: 14 additions & 9 deletions rules/python/shared/django/http_response.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
type: shared
imports:
- python_shared_lang_instance
- python_shared_lang_import2
languages:
- python
patterns:
- pattern: $<HTTP_RESPONSE>
filters:
- variable: HTTP_RESPONSE
detection: python_shared_lang_import2
scope: cursor
detection: python_shared_lang_instance
scope: cursor_strict
filters:
- variable: MODULE1
values: [django]
- variable: MODULE2
values: [http]
- variable: NAME
values: [HttpResponse]
- variable: CLASS
detection: python_shared_lang_import2
scope: cursor
filters:
- variable: MODULE1
values: [django]
- variable: MODULE2
values: [http]
- variable: NAME
values: [HttpResponse]
metadata:
description: "Python Django HTTP Response."
description: "Python Django HTTP Response instance."
id: python_shared_django_http_response
11 changes: 8 additions & 3 deletions tests/python/django/insecure_cookie/testdata/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from django.http import HttpResponse

def bad():
response = HttpResponse()
# bearer:expected python_django_insecure_cookie
HttpResponse.set_cookie("foo", "bar", max_age=None, secure=False, httponly=False)
response.set_cookie("foo", "bar", max_age=None, secure=False, httponly=False)

def ok():
HttpResponse.set_cookie("foo", "bar")
response = HttpResponse()

response.set_cookie("foo", "bar")
# still bad but not for this rule
HttpResponse.set_cookie("foo", "bar", max_age=None, secure=True, httponly=False)
response.set_cookie("foo", "bar", max_age=None, secure=True, httponly=False)

0 comments on commit b2bea82

Please sign in to comment.