Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: CI

on:
push:
branches: [main]
pull_request:

# A new push to a PR makes the in-flight run irrelevant.
concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
backend:
name: Backend — pytest
runs-on: ubuntu-latest
defaults:
run:
working-directory: backend
env:
# The suite mocks the database and the embedding service, so no services are
# needed. AUTH_SECRET is required because `from app.main import app` builds
# Settings at import time, and a non-debug Settings refuses the dev default.
AUTH_SECRET: ci-only-secret-not-used-for-any-real-session
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: "3.13"
cache: pip
cache-dependency-path: backend/requirements.txt

- name: Install dependencies
run: pip install -r requirements.txt

- name: Run tests
run: pytest -q

frontend:
name: Frontend — typecheck, lint, build
runs-on: ubuntu-latest
defaults:
run:
working-directory: frontend
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: "22"
cache: npm
cache-dependency-path: frontend/package-lock.json

- name: Install dependencies
run: npm ci

- name: Typecheck
run: npx tsc --noEmit

- name: Lint
run: npm run lint

- name: Build
run: npm run build
12 changes: 12 additions & 0 deletions backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ CHUNK_OVERLAP=120
EMBEDDING_MODEL=BAAI/bge-small-en-v1.5
EMBEDDING_BATCH_SIZE=32

# Authentication
# REQUIRED whenever DEBUG=false - the app refuses to start without it.
# This value alone signs every session cookie; anyone who knows it can forge a
# session for any user. Generate one with:
# python -c "import secrets; print(secrets.token_urlsafe(48))"
AUTH_SECRET=<generate-a-strong-random-value>
AUTH_COOKIE_NAME=docuquery_session
AUTH_SESSION_DAYS=30
# Cookies are Secure + SameSite=None by default, for a cross-site Vercel -> Railway
# setup. Set to false only for local http development.
AUTH_COOKIE_SECURE=true

# LLM
LLM_PROVIDER=groq
LLM_MODEL=qwen/qwen3.8-27b
Expand Down
30 changes: 29 additions & 1 deletion backend/app/core/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import json
from functools import lru_cache
from pydantic import model_validator
from pydantic_settings import BaseSettings, SettingsConfigDict

# The value auth_secret falls back to when nothing sets AUTH_SECRET. It is a public
# constant in a public repo, so a deployment still carrying it signs session cookies
# with a key anyone can read. _reject_insecure_auth_secret below refuses to build a
# non-debug Settings in that state.
DEV_AUTH_SECRET = "dev-only-change-me"


class Settings(BaseSettings):
model_config = SettingsConfigDict(env_file=".env", extra="ignore")
Expand Down Expand Up @@ -55,7 +62,7 @@ def async_database_url(self) -> str:
ollama_base_url: str = "http://localhost:11434"

# Authentication. Set a strong value in Railway/Vercel environments.
auth_secret: str = "dev-only-change-me"
auth_secret: str = DEV_AUTH_SECRET
auth_cookie_name: str = "docuquery_session"
auth_session_days: int = 30
# Production-safe default for Vercel -> Railway cross-site requests.
Expand Down Expand Up @@ -98,6 +105,27 @@ def allowed_ext_set(self) -> set[str]:
def max_file_size_bytes(self) -> int:
return self.max_file_size_mb * 1024 * 1024

@model_validator(mode="after")
def _reject_insecure_auth_secret(self) -> "Settings":
"""Refuse to build production settings that sign sessions with a known key.

auth_secret is the only input to the session cookie's HMAC, so the shipped
default lets anyone mint a cookie for any user id. Failing here — at
Settings() construction — means the process dies before create_app() wires a
single route, rather than serving forgeable sessions. Debug builds are exempt
so local development needs no setup.
"""
if self.debug:
return self
if not self.auth_secret.strip() or self.auth_secret == DEV_AUTH_SECRET:
raise ValueError(
"AUTH_SECRET is unset or still the development default. Set it to a "
"strong random value (e.g. `python -c \"import secrets; "
"print(secrets.token_urlsafe(48))\"`) in the deployment environment, "
"or set DEBUG=true for local development."
)
return self


@lru_cache
def get_settings() -> Settings:
Expand Down
19 changes: 19 additions & 0 deletions backend/tests/test_security.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import pytest

from app.core.config import DEV_AUTH_SECRET, Settings
from app.core.security import create_session, hash_password, read_session, verify_password


Expand All @@ -12,3 +15,19 @@ def test_session_round_trip_and_tamper_rejection():
token = create_session("user-123")
assert read_session(token) == "user-123"
assert read_session(token + "tampered") is None


@pytest.mark.parametrize("secret", [DEV_AUTH_SECRET, "", " "])
def test_production_settings_reject_a_guessable_auth_secret(secret):
"""A non-debug build must not start with a session key anyone could know."""
with pytest.raises(ValueError, match="AUTH_SECRET"):
Settings(debug=False, auth_secret=secret)


def test_production_settings_accept_a_real_auth_secret():
assert Settings(debug=False, auth_secret="s3kr1t-from-the-deploy-env").auth_secret


def test_debug_settings_still_work_without_an_auth_secret():
"""Local development should need no setup, so debug builds keep the default."""
assert Settings(debug=True, auth_secret=DEV_AUTH_SECRET).auth_secret == DEV_AUTH_SECRET
15 changes: 9 additions & 6 deletions frontend/components/landing/useDemoLoop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ export function useDemoLoop(steps: number, { intervalMs = 1500, holdMs = 3200, a

/** Reveals `text` one character at a time while `active`; shows it in full otherwise. */
export function useTypewriter(text: string, active: boolean, speedMs = 26) {
const [count, setCount] = useState(text.length)
const [count, setCount] = useState(active ? 0 : text.length)
// Rewinding belongs in render, not in an effect: an effect would let the browser
// paint the previous line's length for a frame before snapping back to zero.
const [inputs, setInputs] = useState({ text, active })
if (inputs.text !== text || inputs.active !== active) {
setInputs({ text, active })
setCount(active ? 0 : text.length)
}

useEffect(() => {
if (!active) {
setCount(text.length)
return
}
setCount(0)
if (!active) return
let typed = 0
const id = setInterval(() => {
typed += 1
Expand Down
Loading