Skip to content

fix: resolve remaining security and runtime issues - #72

Merged
hacksynth merged 5 commits into
mainfrom
codex/remaining-issues
May 2, 2026
Merged

hacksynth merged 5 commits into
mainfrom
codex/remaining-issues

Conversation

@hacksynth

Copy link
Copy Markdown
Owner

Closes #50
Closes #53
Closes #55

Summary

  • unify Node.js runtime/config/docs/CI on the Node 22 LTS policy
  • encrypt user AI API keys at rest with mandatory OSE_ENCRYPTION_KEY for new key writes
  • generate per-install desktop Auth.js secrets at runtime instead of shipping shared secrets
  • add settings API tests for encrypted key write/read and legacy plaintext lazy migration

Local verification

  • npx prisma generate --schema src/prisma/schema.prisma
  • npm run typecheck
  • npm run check:bom
  • npm run lint
  • npx vitest run src/test/crypto-secrets.test.ts src/test/api-ai-settings-secrets.test.ts src/test/ai-settings-defaults.test.ts
  • npm test
  • npm run build
  • npm audit --omit=dev --audit-level=high

Note: cargo is not installed in this local environment, so Rust formatting/checks are left to the Tauri CI job.

github-actions Bot and others added 5 commits May 3, 2026 01:24
…nd runtime

- .nvmrc, .node-version: 20 -> 22
- Dockerfile: node:25-alpine -> node:22-alpine
- package.json engines.node: >=18.0.0 -> >=20.0.0
- docs/getting-started.md: Node.js 18+/20 -> 20+/22 LTS
- docs/desktop-app.md: Node.js 20 -> 22 LTS (3 references)
- docs/self-hosting.md: Install Node.js 20 -> 22 LTS
- src-tauri/src/lib.rs: startup error message 20+ -> 22+
- .github/workflows/ci.yml: node-version 20 -> 22 (5 occurrences)
- .github/workflows/tauri-check.yml: node-version 20 -> 22
- .github/workflows/security.yml: node-version 20 -> 22
- .github/workflows/release.yml: node-version 20 -> 22 + release notes 20+ -> 22+
- .github/workflows/android-apk.yml: node-version 20 -> 22

Closes #50

Co-authored-by: hacksynth <hacksynth@users.noreply.github.com>
Remove hardcoded NEXTAUTH_SECRET/AUTH_SECRET from .env.tauri and
generate a unique per-install secret at first sidecar startup.

- resolve_or_create_auth_secret(): reads auth.secret from Tauri app data
  dir; treats empty file as missing and regenerates (no empty-secret bug)
- create_secret_file(): uses create_new(true) + mode(0o600) at creation
  on Unix so permissions are set before any data is written; no
  write-then-chmod race
- write_secret_atomic(): removes any leftover .tmp file before calling
  create_new(true), then atomically renames temp -> final path
- Secret is 32 random bytes, Base64-encoded (44 chars via getrandom +
  base64 crates)
- AUTH_SECRET and NEXTAUTH_SECRET injected into sidecar process env
- docs/desktop-app.md: add Auth Secret section documenting per-platform
  storage paths, format, reuse across restarts, deletion impact, dev mode

Fixes #55

Co-authored-by: hacksynth <hacksynth@users.noreply.github.com>
- Add src/lib/crypto/secrets.ts: AES-256-GCM helpers (encryptSecret,
  decryptSecret, resolveSecret, isEncryptionEnabled, isEncryptedSecret)
- Add apiKeyEncrypted / imageApiKeyEncrypted columns to UserAISettings
  via migration 20260502140000_add_encrypted_api_key_fields
- PUT /api/profile/ai-settings: reject new key submissions with HTTP 503
  when OSE_ENCRYPTION_KEY is absent or invalid; never write plaintext
- GET /api/profile/ai-settings: resolve hasApiKey/masked from encrypted
  columns first, falling back to legacy plaintext for display only
- Read paths (resolveAIConfig, resolveAIImageConfig,
  resolveAIImageConfigFromRequest, resolveAIConfigFromRequest): decrypt
  via resolveSecret; lazy-migrate any legacy plaintext key to encrypted
  storage on first use when OSE_ENCRYPTION_KEY is available
- Without OSE_ENCRYPTION_KEY, legacy plaintext keys are treated as
  unconfigured (not used); users must set the env var and re-enter keys
- Add tests: src/test/crypto-secrets.test.ts (round-trip, unicode,
  tamper resistance, resolveSecret fallback behaviour)
- Update .env.example and docs/self-hosting.md with key setup,
  rotation, and backup guidance

Closes #53

Co-authored-by: hacksynth <hacksynth@users.noreply.github.com>
@hacksynth
hacksynth enabled auto-merge (squash) May 2, 2026 17:32
@hacksynth
hacksynth merged commit 458f129 into main May 2, 2026
11 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant