Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b586375

Browse files
authored
Merge pull request #11 from daghan/master
improving cookie security
2 parents e435fe5 + 5eb4a8b commit b586375

File tree

9 files changed

+18
-18
lines changed

9 files changed

+18
-18
lines changed

app/ch12-forms/final/pypi_org/infrastructure/cookie_auth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
def set_auth(response: Response, user_id: int):
1414
hash_val = __hash_text(str(user_id))
1515
val = "{}:{}".format(user_id, hash_val)
16-
response.set_cookie(auth_cookie_name, val)
16+
response.set_cookie(auth_cookie_name, val, secure=False, httponly=True, samesite='Lax')
1717

1818

1919
def __hash_text(text: str) -> str:
@@ -22,7 +22,7 @@ def __hash_text(text: str) -> str:
2222

2323

2424
def __add_cookie_callback(_, response: Response, name: str, value: str):
25-
response.set_cookie(name, value, max_age=timedelta(days=30))
25+
response.set_cookie(name, value, max_age=timedelta(days=30), secure=False, httponly=True, samesite='Lax')
2626

2727

2828
def get_user_id_via_auth_cookie(request: Request) -> Optional[int]:

app/ch13-validation/final/pypi_org/infrastructure/cookie_auth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
def set_auth(response: Response, user_id: int):
1414
hash_val = __hash_text(str(user_id))
1515
val = "{}:{}".format(user_id, hash_val)
16-
response.set_cookie(auth_cookie_name, val)
16+
response.set_cookie(auth_cookie_name, val, secure=False, httponly=True, samesite='Lax')
1717

1818

1919
def __hash_text(text: str) -> str:
@@ -22,7 +22,7 @@ def __hash_text(text: str) -> str:
2222

2323

2424
def __add_cookie_callback(_, response: Response, name: str, value: str):
25-
response.set_cookie(name, value, max_age=timedelta(days=30))
25+
response.set_cookie(name, value, max_age=timedelta(days=30), secure=False, httponly=True, samesite='Lax')
2626

2727

2828
def get_user_id_via_auth_cookie(request: Request) -> Optional[int]:

app/ch13-validation/starter/pypi_org/infrastructure/cookie_auth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
def set_auth(response: Response, user_id: int):
1414
hash_val = __hash_text(str(user_id))
1515
val = "{}:{}".format(user_id, hash_val)
16-
response.set_cookie(auth_cookie_name, val)
16+
response.set_cookie(auth_cookie_name, val, secure=False, httponly=True, samesite='Lax')
1717

1818

1919
def __hash_text(text: str) -> str:
@@ -22,7 +22,7 @@ def __hash_text(text: str) -> str:
2222

2323

2424
def __add_cookie_callback(_, response: Response, name: str, value: str):
25-
response.set_cookie(name, value, max_age=timedelta(days=30))
25+
response.set_cookie(name, value, max_age=timedelta(days=30), secure=False, httponly=True, samesite='Lax')
2626

2727

2828
def get_user_id_via_auth_cookie(request: Request) -> Optional[int]:

app/ch14_testing/final/pypi_org/infrastructure/cookie_auth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
def set_auth(response: Response, user_id: int):
1414
hash_val = __hash_text(str(user_id))
1515
val = "{}:{}".format(user_id, hash_val)
16-
response.set_cookie(auth_cookie_name, val)
16+
response.set_cookie(auth_cookie_name, val, secure=True, httponly=True, samesite='Lax')
1717

1818

1919
def __hash_text(text: str) -> str:
@@ -22,7 +22,7 @@ def __hash_text(text: str) -> str:
2222

2323

2424
def __add_cookie_callback(_, response: Response, name: str, value: str):
25-
response.set_cookie(name, value, max_age=timedelta(days=30))
25+
response.set_cookie(name, value, max_age=timedelta(days=30), secure=False, httponly=True, samesite='Lax')
2626

2727

2828
def get_user_id_via_auth_cookie(request: Request) -> Optional[int]:

app/ch14_testing/starter/pypi_org/infrastructure/cookie_auth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
def set_auth(response: Response, user_id: int):
1414
hash_val = __hash_text(str(user_id))
1515
val = "{}:{}".format(user_id, hash_val)
16-
response.set_cookie(auth_cookie_name, val)
16+
response.set_cookie(auth_cookie_name, val, secure=False, httponly=True, samesite='Lax')
1717

1818

1919
def __hash_text(text: str) -> str:
@@ -22,7 +22,7 @@ def __hash_text(text: str) -> str:
2222

2323

2424
def __add_cookie_callback(_, response: Response, name: str, value: str):
25-
response.set_cookie(name, value, max_age=timedelta(days=30))
25+
response.set_cookie(name, value, max_age=timedelta(days=30), secure=False, httponly=True, samesite='Lax')
2626

2727

2828
def get_user_id_via_auth_cookie(request: Request) -> Optional[int]:

app/ch15_deploy/final/pypi_org/infrastructure/cookie_auth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
def set_auth(response: Response, user_id: int):
1414
hash_val = __hash_text(str(user_id))
1515
val = "{}:{}".format(user_id, hash_val)
16-
response.set_cookie(auth_cookie_name, val)
16+
response.set_cookie(auth_cookie_name, val, secure=False, httponly=True, samesite='Lax')
1717

1818

1919
def __hash_text(text: str) -> str:
@@ -22,7 +22,7 @@ def __hash_text(text: str) -> str:
2222

2323

2424
def __add_cookie_callback(_, response: Response, name: str, value: str):
25-
response.set_cookie(name, value, max_age=timedelta(days=30))
25+
response.set_cookie(name, value, max_age=timedelta(days=30), secure=False, httponly=True, samesite='Lax')
2626

2727

2828
def get_user_id_via_auth_cookie(request: Request) -> Optional[int]:

app/ch15_deploy/starter/pypi_org/infrastructure/cookie_auth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
def set_auth(response: Response, user_id: int):
1414
hash_val = __hash_text(str(user_id))
1515
val = "{}:{}".format(user_id, hash_val)
16-
response.set_cookie(auth_cookie_name, val)
16+
response.set_cookie(auth_cookie_name, val, secure=False, httponly=True, samesite='Lax')
1717

1818

1919
def __hash_text(text: str) -> str:
@@ -22,7 +22,7 @@ def __hash_text(text: str) -> str:
2222

2323

2424
def __add_cookie_callback(_, response: Response, name: str, value: str):
25-
response.set_cookie(name, value, max_age=timedelta(days=30))
25+
response.set_cookie(name, value, max_age=timedelta(days=30), secure=False, httponly=True, samesite='Lax')
2626

2727

2828
def get_user_id_via_auth_cookie(request: Request) -> Optional[int]:

app/ch16_mongodb/final/pypi_org/infrastructure/cookie_auth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
def set_auth(response: Response, user_id: int):
1414
hash_val = __hash_text(str(user_id))
1515
val = "{}:{}".format(user_id, hash_val)
16-
response.set_cookie(auth_cookie_name, val)
16+
response.set_cookie(auth_cookie_name, val, secure=False, httponly=True, samesite='Lax')
1717

1818

1919
def __hash_text(text: str) -> str:
@@ -22,7 +22,7 @@ def __hash_text(text: str) -> str:
2222

2323

2424
def __add_cookie_callback(_, response: Response, name: str, value: str):
25-
response.set_cookie(name, value, max_age=timedelta(days=30))
25+
response.set_cookie(name, value, max_age=timedelta(days=30), secure=False, httponly=True, samesite='Lax')
2626

2727

2828
def get_user_id_via_auth_cookie(request: Request) -> Optional[int]:

app/ch16_mongodb/starter/pypi_org/infrastructure/cookie_auth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
def set_auth(response: Response, user_id: int):
1414
hash_val = __hash_text(str(user_id))
1515
val = "{}:{}".format(user_id, hash_val)
16-
response.set_cookie(auth_cookie_name, val)
16+
response.set_cookie(auth_cookie_name, val, secure=False, httponly=True, samesite='Lax')
1717

1818

1919
def __hash_text(text: str) -> str:
@@ -22,7 +22,7 @@ def __hash_text(text: str) -> str:
2222

2323

2424
def __add_cookie_callback(_, response: Response, name: str, value: str):
25-
response.set_cookie(name, value, max_age=timedelta(days=30))
25+
response.set_cookie(name, value, max_age=timedelta(days=30), secure=False, httponly=True, samesite='Lax')
2626

2727

2828
def get_user_id_via_auth_cookie(request: Request) -> Optional[int]:

0 commit comments

Comments
 (0)