Skip to content

Cross-Cutting Concerns & Shared Infrastructure

1. Auth, Sessions, CSRF, Turnstile & Shared Secrets

  • No End-User Login Sessions in This Repo: All public pages operate either anonymously (scheduler/index.php, dealflow/offer.php?id=, dealflow/inquiry.php) or via possession of a high-entropy URL token (dealflow/offer.php?token={64-hex}, agreements/sign.php?signatoryId=...&token=...).
  • Server-to-Server Shared Secrets (Inconsistent Headers & Comparison):
    • dealflow/api/form-writer.php: X-Api-Secret vs DEALFLOW_API_SECRET using constant-time hash_equals().
    • dealflow/api/save_dealflow.php & create_offer.php: X-Secret-Key vs DEALFLOW_API_SECRET using non-constant-time !==.
    • scheduler/backend/save_scheduler.php: X-Secret-Key vs SCHEDULER_API_SECRET using non-constant-time !==.
    • Unauthenticated Endpoints: dealflow/backend/delete_json.php, scheduler/backend/delete_json.php, scheduler/backend/auth_start.php, scheduler/backend/auth_callback.php, and dealflow/test_generator.php enforce zero authentication.
  • CSRF & Bot Protection:
    • PLANOVI_MS session (SameSite=None; Secure; HttpOnly) + X-CSRF-TOKEN is enforced ONLY on dealflow/api/save_response.php.
    • Cloudflare Turnstile is rendered ONLY on the final question of Offer Normal Mode (offer.php:1805), omitted in Pricing Mode, and bypassed in save_response.php:47 if turnstile_token is omitted.
    • Neither CSRF nor Turnstile is enforced on scheduler/backend/api.php (even though it requires includes/security.php), dealflow/inquiry.php, or agreements/sign.php.

2. Multi-Tenancy & Data Isolation

  • Flat-File Tenant Partitioning: Tenant configs and token snapshots are stored as individual JSON files in scheduler/data/{id}.json and dealflow/data/{id|token}.json. Path traversal is blocked by strict regex sanitization ([^a-zA-Z0-9_-] or [^a-f0-9]).
  • Supabase Service-Role Writes: scheduler/backend/api.php and dealflow/api/save_response.php write to Supabase PostgREST using Service Role keys (bypassing RLS), trusting company_id/user_id from server-side config JSON (scheduler) or from the client-submitted JSON body (save_response.php:70 — Security Anomaly: client can spoof company_id in save_response.php because it reads $new_response['company_id'] instead of reading company_id from dealflow/data/{offer_id}.json!).
  • Data Exposure Risk: dealflow/data/.htaccess blocks direct HTTP reads, whereas scheduler/data/.htaccess is missing from git while 34 tracked JSON files in scheduler/data/ (and scheduler/backend/data/) contain non-empty Google OAuth access/refresh tokens.

3. Branding Rules (Zone 1 vs. Zone 2) & i18n

  • Canonical Design System (BRANDING_GUIDE.md & AGENTS.md):
    • Zone 1 (Platform UI — GoTrue auth emails, inquiry.php, inquiry-success.php, payment-success.php, unconfigured widget fallbacks): Neutral graphite #09090B/#121215 (dark) & #FAFAFA/#FFFFFF (light), Planovi green #32CA42 (#09090B text on solid #32CA42, #22A830 green text on light), official SVG/PNG from assets/brand/.
    • Zone 2 (Tenant White-Label Widgets — scheduler/index.php, dealflow/offer.php, agreements/sign.php): Dynamic --tenant-primary colors from tenant config, zero hardcoded auxiliary accent colors, WCAG sRGB contrast luminance > 0.42 ? '#09090B' : '#FFFFFF'.
  • Current Codebase Reality (Pre-Migration State):
    • Zero PHP views or HTML email templates have been migrated to the new Zone 1/Zone 2 tokens yet. All files still use legacy #0F172A / #1E293B / #14B8A6 / #2DD4BF defaults, hardcoded --accent-blue: #14B8A6, hardcoded #FFFFFF on selected calendar days/slots (scheduler/index.php:975, 984), linear RGB luminance with threshold 0.5 (offer.php:1722, scheduler/index.php:1027), and CSS-drawn/emoji logos (⚡ Planovi / hexagon SVG) instead of assets/brand/*.
  • i18n (pl / en):
    • No i18n framework exists. All HTML documents declare lang="pl", with Polish UI copy throughout, except minor hardcoded English strings: "Today" button (scheduler/index.php:693), "-- Select an option --" / "Enter ..." placeholders (scheduler/index.php:1231-1330, script_v2.js:597-696), and English JSON API error messages (save_scheduler.php, save_dealflow.php, create_offer.php, form-writer.php, public_config.php).

4. Global Error Handling, Logging, Retries, Timeouts & Security Guards

  • HTTP Timeouts:
    • includes/security.php (Turnstile): 8s
    • dealflow/offer.php (onboarding_token_status RPC): 5s
    • dealflow/api/save_response.php (dealflow_entries insert): 5s
    • scheduler/backend/api.php (supabaseSlotTaken): 10s; main GET bookings query & POST/PATCH calls have no explicit CURLOPT_TIMEOUT set.
  • Retries: Zero automatic retry loops in PHP or JS; all user-facing forms preserve user input on network/API failure (except scheduler/index.php which uses alert() and keeps form open) to allow manual retry.
  • CORS: All API endpoints under dealflow/api/, dealflow/backend/, and scheduler/backend/ emit Access-Control-Allow-Origin: *.
  • Anti-Cache Headers: Set on offer.php, inquiry.php, payment-success.php, sign.php, scheduler/index.php, public_config.php, create_offer.php, save_dealflow.php (no-store, no-cache, must-revalidate, max-age=0).
  • Logging: Ad-hoc flat-file logs (dealflow/backend/delete_log.txt, scheduler/backend/delete_log.txt, tracked scheduler/backend/api_debug.log — 3,041 lines) plus inline API_DEBUG_TRACE arrays returned to clients in scheduler/backend/api.php.