diff options
| author | Adam Soltys <[email protected]> | 2026-01-22 10:02:37 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-01-22 10:04:20 -0800 |
| commit | b4a2a12c2a6a58b46cb46fc6210650fa1de8a0aa (patch) | |
| tree | 5e18d044178fe2732a9b9ca939c800c81ce93070 | |
| parent | 5567d850d784b0a40dc16a0d95d17193626c971c (diff) | |
| download | coinos-server-b4a2a12c2a6a58b46cb46fc6210650fa1de8a0aa.tar.gz coinos-server-b4a2a12c2a6a58b46cb46fc6210650fa1de8a0aa.zip | |
api key captcha bypass
| -rw-r--r-- | routes/users.ts | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/routes/users.ts b/routes/users.ts index f704da03..59aa0778 100644 --- a/routes/users.ts +++ b/routes/users.ts @@ -26,12 +26,20 @@ import type { ProfilePointer } from "nostr-tools/nip19"; const { host } = new URL(process.env.URL); const relay = encodeURIComponent(config.publicRelay); -const verifyRecaptcha = async (response, ip) => { +const verifyRecaptcha = async (response, req?) => { const { recaptcha: secret } = config; if (!secret) return true; + + // Check for valid API key to bypass captcha + const apiKey = req?.headers?.["x-api-key"]; + if (apiKey && (await db.sIsMember("apikeys", apiKey))) { + return true; + } + if (!response) return false; try { + const ip = req?.headers?.["cf-connecting-ip"] || req?.socket?.remoteAddress; const { success } = await got .post("https://www.google.com/recaptcha/api/siteverify", { form: { @@ -356,7 +364,7 @@ export default { if (ipCount === 1) await db.expire(ipKey, 10); if (ipCount > 30) return res.code(429).send({}); - const recaptchaOk = await verifyRecaptcha(recaptcha, ip); + const recaptchaOk = await verifyRecaptcha(recaptcha, req); if (!recaptchaOk) { return res.code(401).send("failed captcha"); } @@ -420,7 +428,7 @@ export default { try { const { event, challenge, twofa, recaptcha } = req.body; const ip = req.headers["cf-connecting-ip"]; - const recaptchaOk = await verifyRecaptcha(recaptcha, ip); + const recaptchaOk = await verifyRecaptcha(recaptcha, req); if (!recaptchaOk) { return res.code(401).send("failed captcha"); } |
