This repository was archived by the owner on Oct 9, 2026. It is now read-only.
Repository navigation
Conversation
When both env vars are set, the web UI and API require Basic Auth. The KOReader plugin works unchanged by embedding credentials in the server URL (LuaSocket sends them as a Basic Authorization header). KoSync endpoints that already check x-auth-user/x-auth-key stay open so KOReader progress sync keeps working. POST /users/create and GET /syncs/progress, which had no auth, are now protected. Refs Ko-Insight#81, Ko-Insight#12 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
|
Tested on device and sync is all working with server and DB hosted on railway |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #81, #12
What
Adds optional HTTP Basic Auth to the server so KoInsight can be exposed publicly without a reverse proxy. It is off unless both
AUTH_USERNAMEandAUTH_PASSWORDare set, so current deployments are unaffected.Authorizationheader (common/socket/http.lua), so the server URL becomeshttps://user:password@host. That's the same workaround people described in [Feature Request] - Add Native Password / Token Authentication (Required for Secure Public Self-Hosting) #81, now working without a proxy.x-auth-user/x-auth-keystay open (GET /users/auth,PUT /syncs/progress,GET /syncs/progress/:document), so KOReader progress sync keeps working unchanged.POST /users/createandGET /syncs/progresshad no auth at all, so they now require Basic Auth. Otherwise anyone could register users or list every user's progress.Credentials are compared in constant time (hash, then
timingSafeEqual).Changes
apps/server/src/auth/basic-auth-middleware.ts: the new middleware, plus testsconfig.ts/app.ts: read the env vars and mount the middleware.env.example: document the env vars and how to set up each clientTesting
/,/api/booksand/syncs/progressreturn 401 with aWWW-Authenticateheader, and a wrong password also returns 401. With valid credentials, the UI and API return 200. KoSync's self-authenticated routes return their own JSON errors.https://user:pass@…. The device registered and its reading stats were uploaded.Unrelated issue found while deploying
Current
mastercrashes at startup in Docker:Cannot find module '@koinsight/common/utils/ranges'. #124 madebooks-service.tsimport runtime code frompackages/common, but the runner stage only copiesnode_modules, where@koinsight/commonis a symlink topackages/common, which isn't copied. Even if it were, that package holds uncompiled.ts. v0.2.3 isn't affected. I left it out of this PR, and I'm happy to open a separate issue or PR.A separate flaky test, also unrelated:
stats-service.test.ts > mostPagesInADaysometimes hits a UNIQUE constraint onpage_stat. It happens about once in 10 runs because random factory data collides.🤖 Generated with Claude Code