Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
mclmax committed Oct 25, 2024
1 parent ba804f8 commit 4634e4b
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ jobs:
touch .env
echo VITE_GITHUB_SHA=${GITHUB_SHA} >> .env
echo VITE_GOOGLE_MAPS_API_KEY="${{ secrets.GOOGLE_MAPS_API_KEY_DEV }}" >> .env
echo VITE_CLOUDFLARE_TURNSTILE_SITE_KEY="${{ secrets.CLOUDFLARE_TURNSTILE_SITE_KEY_DEV }}" >> .env
cat .env
- name: Include git Google Maps Key for Frontend Production release
Expand All @@ -65,6 +66,7 @@ jobs:
run: |
touch .env
echo VITE_GOOGLE_MAPS_API_KEY="${{ secrets.GOOGLE_MAPS_API_KEY_PROD }}" >> .env
echo VITE_CLOUDFLARE_TURNSTILE_SITE_KEY="${{ secrets.CLOUDFLARE_TURNSTILE_SITE_KEY_PROD }}" >> .env
cat .env
- name: Build Frontend Dist
Expand Down
1 change: 1 addition & 0 deletions canarytokens/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,7 @@ class WindowsDirectoryTokenRequest(TokenRequest):

class CreditCardV2TokenRequest(TokenRequest):
token_type: Literal[TokenTypes.CREDIT_CARD_V2] = TokenTypes.CREDIT_CARD_V2
cf_turnstile_response: Optional[str]


AnyTokenRequest = Annotated[
Expand Down
1 change: 1 addition & 0 deletions canarytokens/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class FrontendSettings(BaseSettings):
CREDIT_CARD_INFRA_ACCOUNT_ID: Optional[str]
CREDIT_CARD_INFRA_REGION: Optional[str]
CREDIT_CARD_INFRA_ACCESS_ROLE: Optional[str]
CLOUDFLARE_TURNSTILE_SECRET: Optional[str]

class Config:
allow_mutation = False
Expand Down
17 changes: 17 additions & 0 deletions frontend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,23 @@ async def api_generate( # noqa: C901 # gen is large
6,
"Blocked email supplied. Please see our Acceptable Use Policy at https://canarytokens.org/legal",
)

if token_request_details.token_type == TokenTypes.CREDIT_CARD_V2:
token = token_request_details.cf_turnstile_response
if token is None:
return JSONResponse({"message": "failure"}, status_code=401)

data = {
"secret": frontend_settings.CLOUDFLARE_TURNSTILE_SECRET,
"response": token,
}
result = requests.post(
"https://challenges.cloudflare.com/turnstile/v0/siteverify", data=data
).json()

if not result.get("success", False):
return JSONResponse({"message": "failure"}, status_code=401)

# TODO: refactor this. KUBECONFIG token creates it's own token
# value and cannot follow same path as before.
if token_request_details.token_type == TokenTypes.KUBECONFIG:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
<template>
<GenerateTokenSettingsNotifications
memo-helper-example="Credit Card placed in payment card database" />
<vue-turnstile site-key="0x4AAAAAAAyZHnv6R_-lfIea" v-model="token" />
<div>Token: {{ token }}</div>
<vue-turnstile :site-key="cloudflareSiteKey" v-model="cloudflareToken" />
{{ cloudflareToken }}
</template>

<script setup lang="ts">
import { ref } from 'vue';
import type { Ref } from 'vue';
import GenerateTokenSettingsNotifications from '@/components/ui/GenerateTokenSettingsNotifications.vue';
import VueTurnstile from 'vue-turnstile';
const cloudflareToken: Ref<string> = ref('');
const cloudflareSiteKey = import.meta.env.VITE_CLOUDFLARE_TURNSTILE_SITE_KEY;
const token = ref();
</script>
6 changes: 6 additions & 0 deletions frontend_vue/src/utils/formValidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,10 @@ export const formValidators: ValidateSchemaType = {
),
}),
},
[TOKENS_TYPE.CREDIT_CARD_V2]: {
schema: Yup.object().shape({
...validationNotificationSettings,
'cf-turnstile-response': Yup.string().required('Cloudflare turnstile response required.'),
}),
},
};

0 comments on commit 4634e4b

Please sign in to comment.