-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(auth): add opt-in local login bypass #1042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,76 @@ | ||||||||||||||||||
| import assert from 'node:assert/strict'; | ||||||||||||||||||
| import { mkdtemp, rm } from 'node:fs/promises'; | ||||||||||||||||||
| import os from 'node:os'; | ||||||||||||||||||
| import path from 'node:path'; | ||||||||||||||||||
| import test from 'node:test'; | ||||||||||||||||||
|
|
||||||||||||||||||
| process.env.JWT_SECRET = 'test-secret'; | ||||||||||||||||||
| process.env.DISABLE_AUTH = 'true'; | ||||||||||||||||||
|
|
||||||||||||||||||
| const temporaryDirectory = await mkdtemp(path.join(os.tmpdir(), 'cloudcli-auth-bypass-')); | ||||||||||||||||||
| process.env.DATABASE_PATH = path.join(temporaryDirectory, 'auth.db'); | ||||||||||||||||||
|
|
||||||||||||||||||
| const { initializeDatabase } = await import('../modules/database/init-db.js'); | ||||||||||||||||||
| const { closeConnection } = await import('../modules/database/connection.js'); | ||||||||||||||||||
| const { userDb } = await import('../modules/database/index.js'); | ||||||||||||||||||
| const { authenticateToken, authenticateWebSocket, getLocalBypassUser } = await import('./auth.js'); | ||||||||||||||||||
| const { verifyWebSocketClient } = await import('../modules/websocket/services/websocket-auth.service.ts'); | ||||||||||||||||||
|
|
||||||||||||||||||
| await initializeDatabase(); | ||||||||||||||||||
|
|
||||||||||||||||||
| test.after(async () => { | ||||||||||||||||||
| closeConnection(); | ||||||||||||||||||
| await rm(temporaryDirectory, { recursive: true, force: true }); | ||||||||||||||||||
| }); | ||||||||||||||||||
|
|
||||||||||||||||||
| test('authentication bypass fails closed until a local user exists', async () => { | ||||||||||||||||||
| assert.equal(getLocalBypassUser(), undefined); | ||||||||||||||||||
| assert.equal(authenticateWebSocket(null), null); | ||||||||||||||||||
|
|
||||||||||||||||||
| let statusCode = null; | ||||||||||||||||||
| let responseBody = null; | ||||||||||||||||||
| await authenticateToken({}, { | ||||||||||||||||||
| status(code) { | ||||||||||||||||||
| statusCode = code; | ||||||||||||||||||
| return this; | ||||||||||||||||||
| }, | ||||||||||||||||||
| json(body) { | ||||||||||||||||||
| responseBody = body; | ||||||||||||||||||
| return this; | ||||||||||||||||||
| }, | ||||||||||||||||||
| }, () => assert.fail('middleware must not continue without a local user')); | ||||||||||||||||||
|
|
||||||||||||||||||
| assert.equal(statusCode, 503); | ||||||||||||||||||
| assert.match(responseBody.error, /existing local user/i); | ||||||||||||||||||
| }); | ||||||||||||||||||
|
|
||||||||||||||||||
| test('authentication bypass uses the existing single local user', async () => { | ||||||||||||||||||
| userDb.createUser('admin', 'existing-password-hash'); | ||||||||||||||||||
|
|
||||||||||||||||||
| const socketUser = authenticateWebSocket(null); | ||||||||||||||||||
| assert.equal(socketUser.username, 'admin'); | ||||||||||||||||||
|
|
||||||||||||||||||
| const request = {}; | ||||||||||||||||||
| let continued = false; | ||||||||||||||||||
| await authenticateToken(request, {}, () => { | ||||||||||||||||||
| continued = true; | ||||||||||||||||||
| }); | ||||||||||||||||||
|
|
||||||||||||||||||
| assert.equal(continued, true); | ||||||||||||||||||
| assert.equal(request.user.username, 'admin'); | ||||||||||||||||||
| }); | ||||||||||||||||||
|
|
||||||||||||||||||
| test('authentication bypass accepts WebSocket upgrades without a token', () => { | ||||||||||||||||||
| const request = { | ||||||||||||||||||
| url: '/ws', | ||||||||||||||||||
| headers: {}, | ||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| const accepted = verifyWebSocketClient({ req: request }, { | ||||||||||||||||||
| isPlatform: true, | ||||||||||||||||||
| authenticateWebSocket, | ||||||||||||||||||
| }); | ||||||||||||||||||
|
Comment on lines
+69
to
+72
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Test the OSS token extraction path, not platform mode. The 💚 Proposed fix const accepted = verifyWebSocketClient({ req: request }, {
- isPlatform: true,
+ isPlatform: false,
authenticateWebSocket,
});📝 Committable suggestion
Suggested change
🤖 Prompt for AI AgentsSource: Path instructions |
||||||||||||||||||
|
|
||||||||||||||||||
| assert.equal(accepted, true); | ||||||||||||||||||
| assert.equal(request.user.username, 'admin'); | ||||||||||||||||||
| }); | ||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: siteboon/claudecodeui
Length of output: 208
🏁 Script executed:
Repository: siteboon/claudecodeui
Length of output: 3490
🏁 Script executed:
Repository: siteboon/claudecodeui
Length of output: 8706
Use
isPlatform: falsein the WebSocket bypass test.This test should exercise the OSS/local bypass path, not the platform branch.
🤖 Prompt for AI Agents