Server Internals
CookieFarm server internals process lifecycle, API, CKP, DB and submission loops.
Server Internals
Boot Sequence (cks)
- load env/config and logger
- initialize SQLite DB + store
- initialize runner (
core.Runner) - start CKP TCP server on port
7777 - create Fiber app and static frontend fallback
- register API routes
- start HTTP server and graceful shutdown handlers
Files: cookiefarm/server/cmd/root.go, server/api/server.go.
Authentication Model
- login via
POST /api/v1/auth/login - JWT stored in cookie
token - JWT accepted from cookie or
Authorization: Bearer
Protected API endpoints reject unauthenticated requests. The frontend handles login state through the API.
Essential Route Map
Public:
GET /api/v1/POST /api/v1/auth/loginPOST /api/v1/auth/logoutGET /api/v1/auth/verifyGET /api/v1/protocolsGET /api/v1/swaggerGET /api/v1/swagger/doc.json
Private (JWT):
GET /api/v1/configGET /api/v1/config/fullPOST /api/v1/configPOST /api/v1/submit-flagPOST /api/v1/submit-flagsPOST /api/v1/submit-flags-standaloneDELETE /api/v1/delete-flagGET /api/v1/flags*GET /api/v1/statsGET /api/v1/exploitsGET /api/v1/exploit/:namePOST /api/v1/exploit/uploadDELETE /api/v1/exploit/:id
Frontend:
GET /*serves the React/Vite app unless the path is an API/static asset path.
Concurrency Model
HTTP path
Fiber handles concurrent requests; DB store is shared safely through Go SQL driver primitives.
CKP path
CKP is the default live flag ingestion path:
- raw TCP listener on port
7777 - compact binary flag frames delimited by
0xBB 0x54 0xCC - worker pool for accepted TCP connections
- connected clients registry for config broadcasts
- newline-delimited shared config JSON from server to client after
POST /api/v1/config
Flag collector path
FlagCollector uses mutex + timer + conditional flush.
Flush triggers:
- buffer full
- periodic timer
- collector stop
Runner internals
core.Runner starts two cancellable loops:
- submit loop (
StartFlagProcessingLoop) - optional TTL cleanup (
ValidateFlagTTL)
When config is updated from dashboard (POST /api/v1/config), runner restarts with a new context.
DB Model
Main table: flags.
Key fields:
flag_codePKstatussubmit_timeresponse_timeservice_name,team_id,exploit_name
Dedup semantics: INSERT OR IGNORE by flag_code.
Frontend
The server serves the React/Vite frontend from cookiefarm/server/frontend. Data is loaded through REST endpoints under /api/v1.
Operational Notes
CONFIG_FILE=trueenablesconfig.ymlbootstrap.- If web config is incomplete (
url_flag_checkerempty), submit API stores flags but cannot forward them to checker. flag_ttlis in ticks, not absolute seconds.- CKP has no transport authentication or encryption; expose port
7777only on trusted networks or through a controlled tunnel.
How is this guide?