Skip to content

Commit 88d771b

Browse files
committed
chore: rename altcha session timeout env variable
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
1 parent 0a06cbb commit 88d771b

4 files changed

Lines changed: 9 additions & 9 deletions

File tree

vulnerabilities/middleware/altcha_protection.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from django.shortcuts import redirect
1414
from django.utils.deprecation import MiddlewareMixin
1515

16-
from vulnerablecode.settings import ALTCHA_SESSION_TIMEOUT
16+
from vulnerablecode.settings import VULNERABLECODE_ALTCHA_SESSION_TIMEOUT
1717

1818
ALTCHA_PROTECTED_PREFIXES = (
1919
"/packages/",
@@ -26,7 +26,7 @@
2626

2727
class AltchaProtectionMiddleware(MiddlewareMixin):
2828
def __call__(self, request):
29-
if not ALTCHA_SESSION_TIMEOUT:
29+
if not VULNERABLECODE_ALTCHA_SESSION_TIMEOUT:
3030
return self.get_response(request)
3131

3232
protected = any(request.path.startswith(prefix) for prefix in ALTCHA_PROTECTED_PREFIXES)
@@ -40,7 +40,7 @@ def __call__(self, request):
4040
if not verified_at:
4141
return redirect(f"/altcha/?{urlencode({'next': next_url})}")
4242

43-
if time.time() - verified_at > ALTCHA_SESSION_TIMEOUT:
43+
if time.time() - verified_at > VULNERABLECODE_ALTCHA_SESSION_TIMEOUT:
4444
request.session.pop("altcha_verified_at", None)
4545
return redirect(f"/altcha/?{urlencode({'next': next_url})}")
4646

vulnerabilities/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
from vulnerabilities.utils import get_advisories_from_groups
6666
from vulnerabilities.utils import safe_altcha_redirect
6767
from vulnerablecode import __version__ as VULNERABLECODE_VERSION
68-
from vulnerablecode.settings import ALTCHA_SESSION_TIMEOUT
68+
from vulnerablecode.settings import VULNERABLECODE_ALTCHA_SESSION_TIMEOUT
6969
from vulnerablecode.settings import env
7070

7171
PAGE_SIZE = 10
@@ -1166,7 +1166,7 @@ def dispatch(self, request, *args, **kwargs):
11661166
verified_at = request.session.get("altcha_verified_at")
11671167

11681168
if verified_at:
1169-
if time.time() - verified_at < ALTCHA_SESSION_TIMEOUT:
1169+
if time.time() - verified_at < VULNERABLECODE_ALTCHA_SESSION_TIMEOUT:
11701170
next_url = request.GET.get("next", "/")
11711171
return safe_altcha_redirect(next_url)
11721172

vulnerablecode/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
ALTCHA_HMAC_KEY = env.str("ALTCHA_HMAC_KEY")
4444

45-
ALTCHA_SESSION_TIMEOUT = env.int("ALTCHA_SESSION_TIMEOUT", None)
45+
VULNERABLECODE_ALTCHA_SESSION_TIMEOUT = env.int("VULNERABLECODE_ALTCHA_SESSION_TIMEOUT", None)
4646

4747
# SECURITY WARNING: do not run with debug turned on in production
4848
DEBUG = env.bool("VULNERABLECODE_DEBUG", default=False)
@@ -218,7 +218,7 @@
218218

219219
if IS_TESTS:
220220
VULNERABLECODEIO_REQUIRE_AUTHENTICATION = False
221-
ALTCHA_SESSION_TIMEOUT = 900
221+
VULNERABLECODE_ALTCHA_SESSION_TIMEOUT = 900
222222

223223
USE_L10N = True
224224

vulnerablecode/urls.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
from vulnerabilities.views import PipelineRunDetailView
4141
from vulnerabilities.views import PipelineRunListView
4242
from vulnerabilities.views import PipelineScheduleListView
43-
from vulnerablecode.settings import ALTCHA_SESSION_TIMEOUT
4443
from vulnerablecode.settings import DEBUG
4544
from vulnerablecode.settings import DEBUG_TOOLBAR
45+
from vulnerablecode.settings import VULNERABLECODE_ALTCHA_SESSION_TIMEOUT
4646

4747

4848
# See the comment at https://stackoverflow.com/a/46163870.
@@ -175,7 +175,7 @@ def __init__(self, *args, **kwargs):
175175
# ),
176176
]
177177

178-
if ALTCHA_SESSION_TIMEOUT:
178+
if VULNERABLECODE_ALTCHA_SESSION_TIMEOUT:
179179
urlpatterns += [path("altcha/", AltchaView.as_view(), name="altcha")]
180180

181181
if DEBUG:

0 commit comments

Comments
 (0)