-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add SAST; address findings * update contrib doc * increase cookie security * add custom semgrep rules * add semgrep rule to require auth on handlers * bump version * install semgrep in github action * semgrep rule: use metavars
- Loading branch information
Showing
9 changed files
with
107 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.7.3 | ||
0.7.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,11 +80,14 @@ def ui_method_sort_events_by_date( | |
class AnonymousLoginHandler(UIBaseHandler): | ||
"""Handles "logging in" the UI when no auth is actually configured""" | ||
|
||
# nosemgrep: test.boardwalk.python.security.handler-method-missing-authentication | ||
async def get(self): # pyright: reportIncompatibleMethodOverride=false | ||
self.set_secure_cookie( | ||
"boardwalk_user", | ||
"[email protected]", | ||
expires_days=self.settings["auth_expire_days"], | ||
samesite="Strict", | ||
secure=True, | ||
) | ||
return self.redirect( | ||
self.get_query_argument("next", "/") | ||
|
@@ -97,6 +100,7 @@ class GoogleOAuth2LoginHandler(UIBaseHandler, tornado.auth.GoogleOAuth2Mixin): | |
|
||
url_encryption_key = Fernet.generate_key() | ||
|
||
# nosemgrep: test.boardwalk.python.security.handler-method-missing-authentication | ||
async def get(self, *args: Any, **kwargs: Any): | ||
try: | ||
# If the request is sent along with a code, then we assume the code | ||
|
@@ -118,6 +122,8 @@ async def get(self, *args: Any, **kwargs: Any): | |
"boardwalk_user", | ||
user["email"], | ||
expires_days=self.settings["auth_expire_days"], | ||
samesite="Strict", | ||
secure=True, | ||
) | ||
|
||
# We attempt to redirect back to the original URL the user was browsing | ||
|
@@ -381,6 +387,7 @@ class AuthApiDenied(APIBaseHandler): | |
"""Dedicated handler for redirecting an unauthenticated user to an 'access | ||
denied' endpoint""" | ||
|
||
# nosemgrep: test.boardwalk.python.security.handler-method-missing-authentication | ||
def get(self): | ||
return self.send_error(403) | ||
|
||
|
@@ -591,6 +598,7 @@ def make_server( | |
"url": url, | ||
"websocket_ping_interval": 10, | ||
"xsrf_cookies": True, | ||
"xsrf_cookie_kwargs": {"samesite": "Strict", "secure": True}, | ||
} | ||
if develop: | ||
settings["debug"] = True | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--- | ||
rules: | ||
- id: boardwalk.python.security.insecure-set-secure-cookie | ||
severity: ERROR | ||
languages: | ||
- python | ||
message: | | ||
UIBaseHandler.set_secure_cookie() should have additional arguments passed to | ||
further enhance the security of cookies | ||
Example: | ||
self.set_secure_cookie("boardwalk_user", | ||
"[email protected]", | ||
expires_days=self.settings["auth_expire_days"], | ||
samesite="Strict", secure=True) | ||
patterns: | ||
- pattern: | | ||
class $C(UIBaseHandler): | ||
def $F(...): | ||
... | ||
self.set_secure_cookie(...) | ||
... | ||
- pattern-not: | | ||
class $C(UIBaseHandler): | ||
def $F(...): | ||
... | ||
self.set_secure_cookie( | ||
samesite="Strict", | ||
secure=True, | ||
expires_days=..., | ||
... | ||
) | ||
... | ||
- id: boardwalk.python.security.handler-method-missing-authentication | ||
severity: ERROR | ||
languages: | ||
- python | ||
message: | | ||
UIBaseHandler or APIBaseHandler HTTP methods must require authentication | ||
by using the @tornado.web.authenticated decorator, unless they have been | ||
intentionally excluded | ||
patterns: | ||
- metavariable-pattern: | ||
metavariable: $HANDLER | ||
patterns: | ||
- pattern-either: | ||
- pattern: UIBaseHandler | ||
- pattern: APIBaseHandler | ||
- metavariable-pattern: | ||
metavariable: $METHOD | ||
patterns: | ||
- pattern-either: | ||
- pattern: head | ||
- pattern: get | ||
- pattern: post | ||
- pattern: delete | ||
- pattern: patch | ||
- pattern: put | ||
- pattern: options | ||
- pattern-inside: | | ||
class $C($HANDLER): | ||
... | ||
- pattern: | | ||
def $METHOD(...): | ||
... | ||
- pattern-not: | | ||
@tornado.web.authenticated | ||
def $METHOD(...): | ||
... |