← Documentation · Security & data · LGPD · Measurement

Security · posture

Security posture

Threat model and control boundaries for Compre Barato Alagoas — for reviews, scanners, and anyone assessing whether open source is compatible with production.

Summary: the application API is public by design (the Flutter/web app is an untrusted client). The code can remain open source. Protection does not come from hiding routes on GitHub; it comes from secrets outside the repository, admin closed by default, abuse limits, data minimization (LGPD), and disabling the interactive OpenAPI UI in production. Markdown version in the repository: docs/security-posture.md.

1. What is public on purpose

SurfaceWhyPrimary control
Code on GitHub (MIT)Transparency, LGPD, civic reuseSecrets never in git (.env.example only)
POST /api/v1/search and product routesThe app needs the backendRate limit, validation, cache, no extra PII
docs.* siteProduct and privacyNo credentials
Prices (SEFAZ-AL origin)Public NFC-e dataSEFAZ token only on the server

Typical scanner finding: “Documented API / visible endpoints.”
Response: the client already reveals the contract. Open source and product docs do not replace authentication or limits — and are not a vulnerability by themselves if the controls below are active.

2. What is not a security boundary

3. Surfaces and controls

Application API

Admin API (/admin/api/*)

Secrets

ADMIN_TOKEN, SECRET_ENCRYPTION_KEY, SEFAZ token, Anthropic key, and DB passwords live in the .env only on the VPS (or encrypted panel) — never in git or the client app. API published on the host only at 127.0.0.1:8000 behind nginx.

LLM / SEFAZ

4. OpenAPI / Swagger in production

Environment/docs, /redoc, /openapi.json
development (local)On
production (deploy)Off (404)
EXPOSE_API_DOCS=trueOn (escape hatch)
EXPOSE_API_DOCS=falseOff

App nginx only proxies /api and /health — it does not publish an interactive explorer at the edge. Product-language endpoints remain under Documentation → API.

Important: turning off OpenAPI does not hide the app contract; it reduces noise in automated pentests and avoids an unnecessary exploration console on the same host as the API.

5. Frequent findings

FindingSeverity we adoptTreatment
Public / “documented” APIInformational if section 3 is OKKeep open source; cite this doc; ensure section 4 in prod
OpenAPI in productionLow/medium hygieneOff by default in production
Admin without authenticationCritical if token empty and sensitive dataFail-closed; strong token on the VPS
Secret in the repositoryCriticalRotate; never commit .env
Abuse / LLM costMedium operationalRate limit, cache, monitor admin
Prompt injectionMediumHardened prompt + fallback + tests

6. Quick checklist

  1. With ENVIRONMENT=production: GET /docs and /openapi.json404.
  2. /admin/api/... without token → 401.
  3. No real .env or SEFAZ token in the public repository.
  4. Redis/Postgres only on the compose network; API only localhost on the host.
  5. CORS_ORIGINS restricted in production (not * for sensitive scenarios).
  6. Privacy aligned with the code (hashes, consent for cloud lists).

7. Why open source

  1. Prices are already public (SEFAZ-AL); the value is in the secure bridge and honest UX.
  2. LGPD claims remain auditable.
  3. Closing GitHub does not close the app's HTTPS API.

Restricted to the team (private repo or VPS only): operational secrets and internal notes — not this design.

8. Honest limitations

Aligned with code: backend/app/config.py (api_docs_enabled), backend/app/main.py, deploy/nginx/alagoas.precospublicos.ia.br.conf.