BlueGit

timfa filemanager

Make username checks case-insensitive for login and user creation

timfa Tim Falken · pushed by timfa

Authored 2026-05-04 · 6 months ago

Hash
252f784b2b806cb28402f4b062f85d891c27a929
Parent
26e2c9e5
5 files changed +26 −4
.github/technical-reference.md +4 −1
@@ -22,10 +22,13 @@
22 22 - extractCredentials(body) - Accepts encrypted payloads and compatibility plaintext payloads for login/setup.
23 23 - makeAuthResponse(token, clientPublicKey) - Returns encrypted token when client key exists, plaintext token otherwise.
24 24 - POST /api/auth/setup - Creates first admin and issues token.
25 - POST /api/auth/login - Authenticates user and issues token.
25 - POST /api/auth/login - Authenticates user by case-insensitive username match and issues token with canonical stored username.
26 26 - GET /api/auth/me - Returns current authenticated user profile.
27 27 - POST /api/auth/logout - Revokes the active session.
28 28
29 ## server/routes/admin.js
30 - POST /api/admin/users - Creates a new user and enforces case-insensitive username uniqueness.
31
29 32 ## public/app.js
30 33 - showApp() - Reveals app shell; keeps sidebar folded by default on mobile and shows folder overview sidebar on desktop.
31 34 - getOrCreateClientBindingId() - Creates/loads a persistent local browser binding id used in auth fingerprint derivation.
@@ -22,10 +22,13 @@
22- extractCredentials(body) - Accepts encrypted payloads and compatibility plaintext payloads for login/setup.
22- extractCredentials(body) - Accepts encrypted payloads and compatibility plaintext payloads for login/setup.
23- makeAuthResponse(token, clientPublicKey) - Returns encrypted token when client key exists, plaintext token otherwise.
23- makeAuthResponse(token, clientPublicKey) - Returns encrypted token when client key exists, plaintext token otherwise.
24- POST /api/auth/setup - Creates first admin and issues token.
24- POST /api/auth/setup - Creates first admin and issues token.
25- POST /api/auth/login - Authenticates user and issues token.
25- POST /api/auth/login - Authenticates user by case-insensitive username match and issues token with canonical stored username.
26- GET /api/auth/me - Returns current authenticated user profile.
26- GET /api/auth/me - Returns current authenticated user profile.
27- POST /api/auth/logout - Revokes the active session.
27- POST /api/auth/logout - Revokes the active session.
28
28
29## server/routes/admin.js
30- POST /api/admin/users - Creates a new user and enforces case-insensitive username uniqueness.
31
29## public/app.js
32## public/app.js
30- showApp() - Reveals app shell; keeps sidebar folded by default on mobile and shows folder overview sidebar on desktop.
33- showApp() - Reveals app shell; keeps sidebar folded by default on mobile and shows folder overview sidebar on desktop.
31- getOrCreateClientBindingId() - Creates/loads a persistent local browser binding id used in auth fingerprint derivation.
34- getOrCreateClientBindingId() - Creates/loads a persistent local browser binding id used in auth fingerprint derivation.
server/routes/admin.js +1 −1
@@ -47,7 +47,7 @@ router.post('/users', (req, res) =>
47 47 }
48 48
49 49 const db = getDb();
50 const exists = db.prepare('SELECT id FROM users WHERE username = ?').get([username]);
50 const exists = db.prepare('SELECT id FROM users WHERE username = ? COLLATE NOCASE').get([username]);
51 51 if (exists) return res.status(409).json({ error: 'Username already exists.' });
52 52
53 53 const hash = bcrypt.hashSync(password, BCRYPT_ROUNDS);
@@ -47,7 +47,7 @@ router.post('/users', (req, res) =>
47 }
47 }
48
48
49 const db = getDb();
49 const db = getDb();
50 const exists = db.prepare('SELECT id FROM users WHERE username = ?').get([username]);
50 const exists = db.prepare('SELECT id FROM users WHERE username = ? COLLATE NOCASE').get([username]);
51 if (exists) return res.status(409).json({ error: 'Username already exists.' });
51 if (exists) return res.status(409).json({ error: 'Username already exists.' });
52
52
53 const hash = bcrypt.hashSync(password, BCRYPT_ROUNDS);
53 const hash = bcrypt.hashSync(password, BCRYPT_ROUNDS);
server/routes/auth.js +2 −2
@@ -123,7 +123,7 @@ router.post('/login', (req, res) =>
123 123 }
124 124
125 125 const db = getDb();
126 const user = db.prepare('SELECT * FROM users WHERE username = ?').get([username]);
126 const user = db.prepare('SELECT * FROM users WHERE username = ? COLLATE NOCASE').get([username]);
127 127
128 128 if (!user || !bcrypt.compareSync(password, user.password_hash))
129 129 {
@@ -131,7 +131,7 @@ router.post('/login', (req, res) =>
131 131 }
132 132
133 133 const fingerprint = req.body.fingerprint || '';
134 const token = createToken(username, req, fingerprint);
134 const token = createToken(user.username, req, fingerprint);
135 135 res.json(makeAuthResponse(token, req.body.clientPublicKey));
136 136 });
137 137
@@ -123,7 +123,7 @@ router.post('/login', (req, res) =>
123 }
123 }
124
124
125 const db = getDb();
125 const db = getDb();
126 const user = db.prepare('SELECT * FROM users WHERE username = ?').get([username]);
126 const user = db.prepare('SELECT * FROM users WHERE username = ? COLLATE NOCASE').get([username]);
127
127
128 if (!user || !bcrypt.compareSync(password, user.password_hash))
128 if (!user || !bcrypt.compareSync(password, user.password_hash))
129 {
129 {
@@ -131,7 +131,7 @@ router.post('/login', (req, res) =>
131 }
131 }
132
132
133 const fingerprint = req.body.fingerprint || '';
133 const fingerprint = req.body.fingerprint || '';
134 const token = createToken(username, req, fingerprint);
134 const token = createToken(user.username, req, fingerprint);
135 res.json(makeAuthResponse(token, req.body.clientPublicKey));
135 res.json(makeAuthResponse(token, req.body.clientPublicKey));
136});
136});
137
137
tests/admin.routes.test.js +8 −0
@@ -157,6 +157,14 @@ describe('POST /api/admin/users', () =>
157 157 expect(status).toBe(409);
158 158 });
159 159
160 test('rejects duplicate username with different case', async () =>
161 {
162 const { status } = await req('POST', '/api/admin/users', {
163 username: 'BoB', password: 'bobpass3', isAdmin: false, permissions: {},
164 });
165 expect(status).toBe(409);
166 });
167
160 168 test('rejects short password', async () =>
161 169 {
162 170 const { status } = await req('POST', '/api/admin/users', {
@@ -157,6 +157,14 @@ describe('POST /api/admin/users', () =>
157 expect(status).toBe(409);
157 expect(status).toBe(409);
158 });
158 });
159
159
160 test('rejects duplicate username with different case', async () =>
161 {
162 const { status } = await req('POST', '/api/admin/users', {
163 username: 'BoB', password: 'bobpass3', isAdmin: false, permissions: {},
164 });
165 expect(status).toBe(409);
166 });
167
160 test('rejects short password', async () =>
168 test('rejects short password', async () =>
161 {
169 {
162 const { status } = await req('POST', '/api/admin/users', {
170 const { status } = await req('POST', '/api/admin/users', {
tests/auth.routes.test.js +11 −0
@@ -290,6 +290,17 @@ describe('POST /api/auth/login', () =>
290 290 expect(token.split('.').length).toBe(3);
291 291 });
292 292
293 test('accepts login username in different case', async () =>
294 {
295 const encrypted = clientEncrypt({ username: 'AdMiN', password: 'adminpass1' });
296 const { status, body } = await post('/api/auth/login', {
297 encrypted, clientPublicKey: kp.publicKeyJwk, fingerprint: 'test',
298 });
299 expect(status).toBe(200);
300 const token = clientDecrypt(body.encrypted, kp.privateKey);
301 expect(token.split('.').length).toBe(3);
302 });
303
293 304 test('rejects invalid encrypted payload', async () =>
294 305 {
295 306 const { status } = await post('/api/auth/login', {
@@ -290,6 +290,17 @@ describe('POST /api/auth/login', () =>
290 expect(token.split('.').length).toBe(3);
290 expect(token.split('.').length).toBe(3);
291 });
291 });
292
292
293 test('accepts login username in different case', async () =>
294 {
295 const encrypted = clientEncrypt({ username: 'AdMiN', password: 'adminpass1' });
296 const { status, body } = await post('/api/auth/login', {
297 encrypted, clientPublicKey: kp.publicKeyJwk, fingerprint: 'test',
298 });
299 expect(status).toBe(200);
300 const token = clientDecrypt(body.encrypted, kp.privateKey);
301 expect(token.split('.').length).toBe(3);
302 });
303
293 test('rejects invalid encrypted payload', async () =>
304 test('rejects invalid encrypted payload', async () =>
294 {
305 {
295 const { status } = await post('/api/auth/login', {
306 const { status } = await post('/api/auth/login', {