Skip to content

Secrets hygiene: env cookie secret, untrack dev DB, close connection leak - #177

Open
Alvin-Nahabwe wants to merge 16 commits into
mainfrom
fix/secrets-hygiene
Open

Secrets hygiene: env cookie secret, untrack dev DB, close connection leak#177
Alvin-Nahabwe wants to merge 16 commits into
mainfrom
fix/secrets-hygiene

Conversation

@Alvin-Nahabwe

Copy link
Copy Markdown
Contributor

What & why

Three fixes to the auth layer plus a gitleaks config.

1. Cookie-signing secret → environment (the real vulnerability)

server/auth.R hardcoded cookie_password = "aphrcpass1" in this public repo. That value is the key used to sign session cookies — with it public, a session cookie can be forged for any user, independent of the password database. It now reads COOKIE_PASSWORD from the environment and warns loudly if it falls back to the dev default.

Action required on deploy: set COOKIE_PASSWORD in the environment (this also invalidates existing sessions once, which is desired).

2. Untrack the committed dev database

users_db/users.sqlite (throwaway local-test accounts — confirmed no real users) was committed. Untracked it (already covered by .gitignore). Safe because:

  • login::login_server recreates the tables on first run (dbWriteTable when the table is absent), and
  • auth.R now creates the users_db/ directory and only runs its ALTER TABLE users when the table already exists — previously it would have crashed on a fresh DB with "no such table: users".

A fresh clone/deploy now boots cleanly with no committed database.

3. Close the login DB connection

The connection was opened per session and never closed (the "call dbDisconnect()" warnings from issues.md). Now closed on session$onSessionEnded.

4. gitleaks config

.gitleaks.toml allowlists the dev DB path and the dev cookie fallback so the secret scan (added in #176, currently advisory) can be flipped to blocking.

Verified

parse() passes on auth.R. Confirmed login::login_server auto-creates tables and uses salted SHA-512 (via digest) for passwords — the unsalted MD5 123456 hashes were only in the dev fixture, now untracked.

Follow-ups

  • After CI: R parse check and secret scan #176 merges, flip the app's gitleaks job from advisory to blocking (one line).
  • Consider a slow KDF (bcrypt/argon2) for passwords — needs a different auth package than login (which offers SHA-family salt_algo only). Recommendation, not urgent.

Note on history

Per your decision, no history rewrite — the dev DB remains in past commits (it's fake data). The allowlist keeps the scan clean.

🤖 Generated with Claude Code

damiancodes and others added 16 commits July 3, 2026 00:29
  model training

  - Add all caret job queue label keys
Add async caret job queue with concurrent
- cookie_password (the session-cookie signing key) was hardcoded as
  "aphrcpass1" in a public repo, so cookies could be forged. It now reads
  COOKIE_PASSWORD from the environment and warns loudly on the dev
  fallback. Deployments must set COOKIE_PASSWORD.
- users_db/users.sqlite (a throwaway local-test database with dummy
  accounts) was committed. Untracked it; it is already covered by
  .gitignore. login::login_server recreates the tables on first run, and
  auth.R now creates the users_db/ directory and only runs its ALTER
  TABLE when the table already exists, so a fresh deployment boots
  cleanly with no committed database.
- The login database connection was opened per session and never closed
  (the source of the "call dbDisconnect()" warnings). It is now closed on
  session end.
- Added .gitleaks.toml allowlisting the dev DB path and the dev cookie
  fallback so the secret scan can be promoted to a blocking gate.

Note: real password hashing is handled by the login package as salted
SHA-512 (not the unsalted MD5 that was in the dev fixture). Moving to a
slow KDF (bcrypt/argon2) would be stronger but needs a different auth
package - tracked as a follow-up, not included here.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants