Skip to content

Commit e8d2705

Browse files
committed
more debug info for trunstile; remove tron_data
1 parent c6d721e commit e8d2705

2 files changed

Lines changed: 38 additions & 35 deletions

File tree

helpers/services.js

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,24 +194,54 @@ async function verifyCaptcha(turnstileToken, ip) {
194194
if (DEBUG_MODE) {
195195
logger.warn('Verify captcha for %s', ip);
196196
} else {
197+
if (!turnstileSecret || turnstileSecret.trim() === '') {
198+
logger.error('TURNSTILE_SECRET is not configured');
199+
throw new Error('Turnstile secret key is not configured');
200+
}
201+
202+
if (!turnstileToken || turnstileToken.trim() === '') {
203+
throw new Error('Turnstile token is required');
204+
}
205+
197206
const url = `https://challenges.cloudflare.com/turnstile/v0/siteverify`;
198207
const formData = `secret=${encodeURIComponent(
199208
turnstileSecret
200209
)}&response=${encodeURIComponent(
201210
turnstileToken
202211
)}&remoteip=${encodeURIComponent(ip)}`;
203212

204-
const response = await (await fetch(url, {
205-
method: 'POST',
206-
headers: {
207-
'Content-Type': 'application/x-www-form-urlencoded',
208-
},
209-
body: formData,
210-
})).json();
213+
let response;
214+
try {
215+
const fetchResponse = await fetch(url, {
216+
method: 'POST',
217+
headers: {
218+
'Content-Type': 'application/x-www-form-urlencoded',
219+
},
220+
body: formData,
221+
});
222+
response = await fetchResponse.json();
223+
} catch (error) {
224+
logger.error({ error }, 'Failed to verify Turnstile token');
225+
throw new Error('Failed to verify Turnstile token');
226+
}
211227

212228
if (!response.success) {
213229
const errors = response['error-codes'] || ['unknown'];
214-
throw new Error(`Turnstile verification failed: ${errors.join()}`);
230+
logger.warn(
231+
{ errorCodes: errors, ip },
232+
'Turnstile verification failed'
233+
);
234+
235+
// Provide more specific error messages
236+
if (errors.includes('invalid-input-secret')) {
237+
throw new Error(
238+
'Turnstile verification failed: Invalid secret key. Please check TURNSTILE_SECRET configuration.'
239+
);
240+
}
241+
242+
throw new Error(
243+
`Turnstile verification failed: ${errors.join(', ')}`
244+
);
215245
}
216246
}
217247
}

routes/apiHandlers.js

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,7 +1763,6 @@ async function handleCreateAccountNew(req) {
17631763
xref,
17641764
locale,
17651765
activityTags,
1766-
tron_bind_data,
17671766
source, // format: app|tag (eg. condenser|submit_post)
17681767
} = req.body; // eslint-disable-line camelcase
17691768

@@ -1776,11 +1775,6 @@ async function handleCreateAccountNew(req) {
17761775
throw new ApiError({ type: 'error_api_token_required' });
17771776
}
17781777

1779-
if (!tron_bind_data) {
1780-
throw new ApiError({ type: 'error_api_tron_bind_data_required' });
1781-
}
1782-
const tronBindData = JSON.parse(tron_bind_data);
1783-
17841778
let decoded;
17851779

17861780
try {
@@ -1907,27 +1901,6 @@ async function handleCreateAccountNew(req) {
19071901
});
19081902
}
19091903

1910-
try {
1911-
const updateTronUserResult = await updateTronUser(
1912-
decoded.username,
1913-
tronBindData
1914-
);
1915-
req.log.info(
1916-
{ decoded, updateTronUserResult },
1917-
'bind_tron_address_success'
1918-
);
1919-
} catch (cause) {
1920-
req.log.error(
1921-
{ decoded, tronBindData, cause },
1922-
'error_api_bind_tron_addr_failed'
1923-
);
1924-
throw new ApiError({
1925-
type: 'error_api_bind_tron_addr_failed',
1926-
cause,
1927-
status: 500,
1928-
});
1929-
}
1930-
19311904
// try {
19321905
// await services.gatekeeperMarkSignupCreated(user);
19331906
// } catch (error) {

0 commit comments

Comments
 (0)