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-SecretvsDEALFLOW_API_SECRETusing constant-timehash_equals().dealflow/api/save_dealflow.php&create_offer.php:X-Secret-KeyvsDEALFLOW_API_SECRETusing non-constant-time!==.scheduler/backend/save_scheduler.php:X-Secret-KeyvsSCHEDULER_API_SECRETusing 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, anddealflow/test_generator.phpenforce zero authentication.
- CSRF & Bot Protection:
PLANOVI_MSsession (SameSite=None; Secure; HttpOnly) +X-CSRF-TOKENis enforced ONLY ondealflow/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 insave_response.php:47ifturnstile_tokenis omitted. - Neither CSRF nor Turnstile is enforced on
scheduler/backend/api.php(even though it requiresincludes/security.php),dealflow/inquiry.php, oragreements/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}.jsonanddealflow/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.phpanddealflow/api/save_response.phpwrite to Supabase PostgREST using Service Role keys (bypassing RLS), trustingcompany_id/user_idfrom server-side config JSON (scheduler) or from the client-submitted JSON body (save_response.php:70— Security Anomaly: client can spoofcompany_idinsave_response.phpbecause it reads$new_response['company_id']instead of readingcompany_idfromdealflow/data/{offer_id}.json!). - Data Exposure Risk:
dealflow/data/.htaccessblocks direct HTTP reads, whereasscheduler/data/.htaccessis missing from git while 34 tracked JSON files inscheduler/data/(andscheduler/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(#09090Btext on solid#32CA42,#22A830green text on light), official SVG/PNG fromassets/brand/. - Zone 2 (Tenant White-Label Widgets —
scheduler/index.php,dealflow/offer.php,agreements/sign.php): Dynamic--tenant-primarycolors from tenant config, zero hardcoded auxiliary accent colors, WCAG sRGB contrastluminance > 0.42 ? '#09090B' : '#FFFFFF'.
- Zone 1 (Platform UI — GoTrue auth emails,
- 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/#2DD4BFdefaults, hardcoded--accent-blue: #14B8A6, hardcoded#FFFFFFon selected calendar days/slots (scheduler/index.php:975, 984), linear RGB luminance with threshold0.5(offer.php:1722,scheduler/index.php:1027), and CSS-drawn/emoji logos (⚡ Planovi/ hexagon SVG) instead ofassets/brand/*.
- Zero PHP views or HTML email templates have been migrated to the new Zone 1/Zone 2 tokens yet. All files still use legacy
- 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).
- No i18n framework exists. All HTML documents declare
4. Global Error Handling, Logging, Retries, Timeouts & Security Guards
- HTTP Timeouts:
includes/security.php(Turnstile):8sdealflow/offer.php(onboarding_token_statusRPC):5sdealflow/api/save_response.php(dealflow_entriesinsert):5sscheduler/backend/api.php(supabaseSlotTaken):10s; mainGETbookings query &POST/PATCHcalls have no explicitCURLOPT_TIMEOUTset.
- Retries: Zero automatic retry loops in PHP or JS; all user-facing forms preserve user input on network/API failure (except
scheduler/index.phpwhich usesalert()and keeps form open) to allow manual retry. - CORS: All API endpoints under
dealflow/api/,dealflow/backend/, andscheduler/backend/emitAccess-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, trackedscheduler/backend/api_debug.log— 3,041 lines) plus inlineAPI_DEBUG_TRACEarrays returned to clients inscheduler/backend/api.php.