Skip to content

fix(security+seo): harden nginx headers, add SEO meta, robots/sitemap, error monitor - #8

Open
TThranduil1 wants to merge 2 commits into
OpenByteInc:mainfrom
TThranduil1:fix/security-seo-legal
Open

fix(security+seo): harden nginx headers, add SEO meta, robots/sitemap, error monitor#8
TThranduil1 wants to merge 2 commits into
OpenByteInc:mainfrom
TThranduil1:fix/security-seo-legal

Conversation

@TThranduil1

Copy link
Copy Markdown

Summary

Fixes the top security, SEO, and frontend observability gaps found in a live audit of https://quant.kai.com/.

Security (nginx)

  • server_tokens off — stop leaking nginx/1.28.3 (Ubuntu) version
  • Full CSP (default-src 'self'; script-src 'self'; ...) replacing the old frame-ancestors 'self' only
  • HSTS with includeSubDomains; preload (was bare max-age)
  • Add Referrer-Policy: strict-origin-when-cross-origin
  • Add Permissions-Policy: camera=(), microphone=(), geolocation=(), interest-cohort=()
  • Remove deprecated X-XSS-Protection and X-Frame-Options (CSP supersedes them)

SEO

  • index.html: add description, keywords, og:*, twitter:*, canonical, JSON-LD (SoftwareApplication schema), preconnect to API domain
  • Add public/robots.txt + public/sitemap.xml (were returning SPA HTML shell)
  • nginx: serve robots.txt and sitemap.xml as static files

Frontend error monitoring

  • New src/core/error_monitor.js: captures window.onerror, unhandledrejection, resource load failures (capture phase), with reportTradeFailure() and reportStrategyCrash() entry points. Batched (10s) + offline queue + keepalive flush.
  • main.js: import error_monitor first so it catches all downstream errors. Reports to POST /api/v2/errors.

Files changed

  • deploy/nginx-docker.conf.template (Docker production)
  • deploy/nginx-docker.conf
  • deploy/nginx.conf
  • index.html
  • public/robots.txt (new)
  • public/sitemap.xml (new)
  • src/core/error_monitor.js (new)
  • src/main.js

Not in this PR (separate follow-ups)

  • Backend legal defaults (branding.py) — tracked in the backend repo
  • Risk guard integration — tracked in the backend repo
  • WebSocket market feed — tracked in the backend repo

Checklist

  • nginx config syntax reviewed
  • HTML meta tags validated (tags paired, JSON-LD parses, no inline JS except ld+json)
  • robots.txt + sitemap.xml format validated

…, error monitor

- nginx: server_tokens off, full CSP, HSTS+preload, Referrer-Policy,
  Permissions-Policy; remove deprecated X-XSS-Protection and X-Frame-Options
- nginx: serve robots.txt and sitemap.xml from public/
- index.html: add description/keywords/og:*/twitter:*/canonical/JSON-LD
- public/robots.txt + sitemap.xml for SEO crawlability
- src/core/error_monitor.js: window.onerror + unhandledrejection + resource
  errors + trade/strategy crash reporting, batched to /api/v2/errors
- main.js: import error_monitor first so it catches all downstream errors
- New Vue pages: src/views/legal/UserAgreement.vue (10 sections,
  covers AI disclaimer, trading risk, martingale warning, prohibited use)
- New Vue pages: src/views/legal/PrivacyPolicy.vue (11 sections, data
  collection table, AES-256 encryption, user rights, data retention)
- router.config.js: register /legal/* under BlankLayout, hidden from nav
- permission.js: add UserAgreement + PrivacyPolicy to allowList so the
  legal pages are accessible without login (required for compliance)

These pages are referenced by the backend brand-config legal URLs
(/legal/user-agreement, /legal/privacy-policy) and the UserLayout footer
privacy link.
TThranduil1 pushed a commit to TThranduil1/QuantDinger that referenced this pull request Aug 13, 2026
…wire guard into order gateway

### Platform-level risk guard (app/services/risk_guard.py)
- New RiskGuard module: 5 hard rules — drawdown halt (default 20%),
  single-symbol position ratio cap (30%), martingale layer/leverage
  lock (6 layers / 4x), order notional + ratio cap (100k / 10%),
  sliding-window rate limit (20 orders/60s)
- All thresholds configurable via RISK_GUARD_* env vars
- Thread-safe singleton (RiskGuard.shared())
- Fail-open design: if account snapshot is unavailable, guard skips
  rather than blocking trading

### Frontend error monitoring endpoint (app/routes/error_reports.py)
- POST /api/v2/errors — receives batched frontend error events
  (window.onerror, unhandledrejection, resource errors, trade/strategy
  crashes). No auth (errors can happen pre-login). Rate-limited by
  payload size cap (50 events/batch, 4k chars/field)
- GET /api/v2/errors/stats — lightweight ops counter
- Registered in openapi/register.py + tags.py as ErrorReports tag

### Risk guard integration (app/services/strategy_v2/live_execution.py)
- StrategyV2OrderGateway.submit() now calls _check_risk_guard() after
  _validate() and before persisting the pending order
- Fetches best-effort account snapshot to evaluate drawdown/position
  ratio; infers martingale state from action prefix
- Blocked orders raise ValueError('strategyV2.riskGuardBlocked: ...')
  so the caller can surface the reason to the AI strategy review

Related frontend PR: OpenByteInc/QuantDinger-Vue#8 (error_monitor.js
reports to this /api/v2/errors endpoint)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant