detached 38bffed

refactor: Improve registration validation and captcha security

commit
38bffedd1f98af5f51c7ff0454097036a6717db8
author
Kit · · 2025-02-18 06:41 UTC
parent
3d77915
signature
SSH UnverifiedSHA256:H91DFuEG4jpk5edzLA4aUKkpv4zv9Q339ipRmkph6Tk The key is unknown
1 file · +6 -1
M src/routes/api/register/+server.ts +6 -1
@@ -73,7 +73,7 @@ export const POST: RequestHandler = async ({ request }) => {
7373
7474 // Validate PDR captcha
7575 const normalizedAnswer = captchaAnswer.trim().toLowerCase();
76- if (normalizedAnswer !== 'poudlard' && normalizedAnswer !== 'poudlard rp') {
76+ if (normalizedAnswer !== 'point de rencontre') {
7777 attemptData.count++;
7878 attemptData.lastAttempt = now;
7979 captchaAttempts.set(ip, attemptData);
@@ -102,6 +102,11 @@ export const POST: RequestHandler = async ({ request }) => {
102102 return new Response(JSON.stringify({ error: 'All fields must be filled' } as RegisterResponseError), { status: 400 });
103103 }
104104
105+ if (username.length < 3) {
106+ log.warn('Username must be at least 3 characters');
107+ return new Response(JSON.stringify({ error: 'Username must be at least 3 characters' } as RegisterResponseError), { status: 400 });
108+ }
109+
105110 if (username.length > 32) {
106111 log.warn('Username must be at most 32 characters');
107112 return new Response(JSON.stringify({ error: 'Username must be at most 32 characters' } as RegisterResponseError), { status: 400 });
@@ -73,7 +73,7 @@ export const POST: RequestHandler = async ({ request }) => {
73 73
74 // Validate PDR captcha74 // Validate PDR captcha
75 const normalizedAnswer = captchaAnswer.trim().toLowerCase();75 const normalizedAnswer = captchaAnswer.trim().toLowerCase();
76- if (normalizedAnswer !== 'poudlard' && normalizedAnswer !== 'poudlard rp') {76+ if (normalizedAnswer !== 'point de rencontre') {
77 attemptData.count++;77 attemptData.count++;
78 attemptData.lastAttempt = now;78 attemptData.lastAttempt = now;
79 captchaAttempts.set(ip, attemptData);79 captchaAttempts.set(ip, attemptData);
@@ -102,6 +102,11 @@ export const POST: RequestHandler = async ({ request }) => {
102 return new Response(JSON.stringify({ error: 'All fields must be filled' } as RegisterResponseError), { status: 400 });102 return new Response(JSON.stringify({ error: 'All fields must be filled' } as RegisterResponseError), { status: 400 });
103 }103 }
104 104
105+ if (username.length < 3) {
106+ log.warn('Username must be at least 3 characters');
107+ return new Response(JSON.stringify({ error: 'Username must be at least 3 characters' } as RegisterResponseError), { status: 400 });
108+ }
109+
105 if (username.length > 32) {110 if (username.length > 32) {
106 log.warn('Username must be at most 32 characters');111 log.warn('Username must be at most 32 characters');
107 return new Response(JSON.stringify({ error: 'Username must be at most 32 characters' } as RegisterResponseError), { status: 400 });112 return new Response(JSON.stringify({ error: 'Username must be at most 32 characters' } as RegisterResponseError), { status: 400 });

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 3

Tags 8

↑↓ moveenter openesc close