Skip to content

Commit

Permalink
Merge pull request #620 from UnitapApp/fix/requirements/captcha-and-zora
Browse files Browse the repository at this point in the history
modified reading tokens from headers
  • Loading branch information
alimaktabi authored Sep 7, 2024
2 parents e24904b + 67b63e6 commit a55624e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions brightIDfaucet/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from dotenv import load_dotenv
from sentry_sdk.integrations.django import DjangoIntegration

from corsheaders.defaults import default_headers

from faucet.faucet_manager.bright_id_interface import BrightIDInterface

load_dotenv()
Expand Down Expand Up @@ -244,6 +246,15 @@ def before_send(event, hint):
else:
CORS_ALLOW_ALL_ORIGINS = True


# Add Turnstile response headers for CORS
# These headers are required for Cloudflare and HCaptcha Turnstile anti-bot service

CORS_ALLOW_HEADERS = list(default_headers) + [
'cf-turnstile-response',
'hc-turnstile-response',
]

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.0/howto/static-files/

Expand Down
4 changes: 2 additions & 2 deletions core/constraints/captcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def is_observed(self, *args, **kwargs) -> bool:
context["request"]
)

turnstile_token = request_context.data.get("cf-turnstile-response")
turnstile_token = request_context.headers.get("cf-turnstile-response")

return request_context.ip is not None and turnstile_token is not None and cloudflare.is_verified(
turnstile_token, request_context.ip
Expand Down Expand Up @@ -60,7 +60,7 @@ def is_observed(self, *args, **kwargs) -> bool:
context["request"]
)

turnstile_token = request_context.data.get("hc-turnstile-response") or request_context.data.get("cf-turnstile-response")
turnstile_token = request_context.headers.get("hc-turnstile-response")

return request_context.ip is not None and turnstile_token is not None and hcaptcha.is_verified(
turnstile_token, request_context.ip
Expand Down

0 comments on commit a55624e

Please sign in to comment.