Files
HIPCTF2/docs/database/auth-settings.md
T

3.8 KiB

type, title, description, tags, timestamp
type title description tags timestamp
database Auth and Settings Tables refresh_token and setting tables — rotating refresh tokens and site configuration.
database
refresh-token
settings
config
2026-07-21T14:18:00Z

Tables

refresh_token

Column Type Description
id TEXT PK UUID v4.
user_id TEXT FK → user.id (indexed, but no DB-level FK cascade is configured).
token_hash TEXT SHA-256 of the raw refresh token (unique).
issued_at TEXT ISO 8601 timestamp.
expires_at TEXT ISO 8601 timestamp; checked on refresh.
revoked_at TEXT ISO 8601 timestamp or NULL if active.

Refresh token lifecycle

  1. IssueAuthService.login and AuthService.registerFirstAdmin mint a new token via crypto.randomBytes(32).toString('base64url') and store its SHA-256 hash with expires_at = now + JWT_REFRESH_TTL. The raw token is set as an HttpOnly rt cookie and also returned in the login response body.
  2. RotateAuthService.refresh looks up the row by token_hash, asserts it isn't revoked/expired, marks revoked_at = now, and mints a new token in the same transaction. Each token is single-use.
  3. LogoutAuthService.logout looks up by token_hash (from the rt cookie) and sets revoked_at. Already-revoked or unknown tokens are silently ignored.

setting

Column Type Description
key TEXT PK Settings key (see SETTINGS_KEYS below).
value TEXT String value (defaults to empty string).

Read/write access goes through SettingsService (backend/src/modules/settings/settings.module.ts), which exposes get(key, fallback?), set(key, value), and getAll().

Settings keys

Defined in backend/src/config/env.schema.ts (SETTINGS_KEYS) and seeded by SeedSystemData1700000000100:

Key Default Consumed by
pageTitle HIPCTF SystemService.bootstrappageTitle
logo "" SystemService.bootstraplogo
welcomeMarkdown "# Welcome\n\nCreate the first admin..." SystemService.bootstrapwelcomeMarkdown
themeKey classic SystemService.bootstraptheme (overridden via ThemeLoaderService)
defaultChallengeIp 127.0.0.1 SystemService.bootstrapdefaultChallengeIp
registrationsEnabled false SystemService.bootstrapregistrationsEnabled
eventStartUtc now + 60s (ISO) EventStatusService.getStatus
eventEndUtc now + 7d (ISO) EventStatusService.getStatus

See also