Skip to content

Commit

Permalink
Adjust COOKIE_SECURE based on SAMESITE setting
Browse files Browse the repository at this point in the history
  • Loading branch information
SchrodingersGat committed Oct 10, 2024
1 parent cb9a850 commit 9d9ffee
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/docs/start/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ Note that in [debug mode](./intro.md#debug-mode), some of the above settings are
| `INVENTREE_COOKIE_SAMESITE` | `False` | Disable all same-site cookie checks in debug mode |
| `INVENTREE_SESSION_COOKIE_SECURE` | `False` | Disable secure session cookies in debug mode (allow non-https cookies) |

### INVENTREE_COOKIE_SAMESITE vs INVENTREE_SESSION_COOKIE_SECURE

Note that if you set the `INVENTREE_COOKIE_SAMESITE` to `None`, then `INVENTREE_SESSION_COOKIE_SECURE` is automatically set to `True` to ensure that the session cookie is secure! This means that the session cookie will only be sent over secure (https) connections.

### Proxy Settings

If you are running InvenTree behind another proxy, you will need to ensure that the InvenTree server is configured to listen on the correct host and port. You will likely have to adjust the `INVENTREE_ALLOWED_HOSTS` setting to ensure that the server will accept requests from the proxy.
Expand Down
10 changes: 9 additions & 1 deletion src/backend/InvenTree/InvenTree/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1115,10 +1115,18 @@
CSRF_COOKIE_SAMESITE = COOKIE_MODE
SESSION_COOKIE_SAMESITE = COOKIE_MODE

"""Set the SESSION_COOKIE_SECURE value based on the following rules:
- False if the server is running in DEBUG mode
- True if samesite cookie setting is set to 'None'
- Otherwise, use the value specified in the configuration file (or env var)
"""
SESSION_COOKIE_SECURE = (
False
if DEBUG
else get_boolean_setting('INVENTREE_SESSION_COOKIE_SECURE', 'cookie.secure', True)
else (
SESSION_COOKIE_SAMESITE == 'None'
or get_boolean_setting('INVENTREE_SESSION_COOKIE_SECURE', 'cookie.secure', True)
)
)

USE_X_FORWARDED_HOST = get_boolean_setting(
Expand Down

0 comments on commit 9d9ffee

Please sign in to comment.