# Security

## Reporting
Report vulnerabilities to support@syncinfinite.com (subject "SECURITY"). Do not open public issues.

## Controls implemented in v0.1.0

| Area | Control |
|---|---|
| SQL injection | Procedural MySQLi with **no string concatenation of raw input**. All values pass through `sql_str()` (escaped with `mysqli_real_escape_string` after `mysqli_set_charset('utf8mb4')`), `sql_int()`/`sql_dec()`/`sql_date()` (strict regex validation, throw on anything else), `sql_ids()`, `sql_like()` (wildcards escaped). Identifiers via `sql_ident()` (regex allow-list); sorting via `sql_order()` allow-lists. `db_insert()/db_update()` build statements from validated keys. Second-order: stored values are re-encoded every time they are used. Static tests U-STA-01..03 enforce the rules. |
| Tenant isolation | Tenant context only from the server session or API key (`current_tenant_id()`); every query filters by `tenant_id`; composite foreign keys `(tenant_id, id)` make cross-tenant references impossible at the DB level; location scoping via `allowed_location_ids()`. |
| AuthN | `password_hash()`/`password_verify()` (bcrypt default, auto-rehash), login throttling per email and per IP, generic error messages + constant-time path for unknown users, session ID regeneration on login, server-side session registry (revocation, "sign out other devices"), idle timeout, HttpOnly + Secure + SameSite=Lax cookies, strict session mode. |
| AuthZ | 58 granular permissions; `require_perm()` in every handler (static test U-STA-04); role limits for discounts/refunds; manager approval (PIN/password of a user who holds the permission); users cannot grant permissions they lack; only owners grant owner. |
| CSRF | Per-session token on every POST (router-enforced) and `X-CSRF-Token` for Fetch calls. |
| XSS | All output through `e()`; strict CSP (`script-src 'self'`, no inline script/style — static test U-STA-07); receipts render data, never markup (U-SEC-07). |
| Headers | CSP, X-Frame-Options, nosniff, Referrer-Policy, Permissions-Policy, HSTS on HTTPS. |
| Uploads | Logos only: PNG/JPEG verified by `getimagesize`, ≤500 KB, random file names, PHP execution disabled in `public/assets/uploads`. |
| Payments | No PAN, CVV, track or PIN data is accepted, stored or logged. Simulated processor is disabled unless `PAYMENTS_SIMULATOR_ENABLED=true`. |
| Gift cards / API keys | Stored as SHA-256 hashes; shown once. Gift card lookups are throttled. |
| Webhooks | HMAC-SHA256 signatures with timestamp; HTTPS only; private/reserved IP targets rejected (SSRF). |
| CSV exports | Formula injection neutralized (U-SEC-05). |
| Audit | Append-only `audit_events` with before/after, IP, request ID, support-access flag; secrets masked. |
| Support access | Time-limited, reason required, read-only, banner shown, tenant owner notified, audited. |
| Secrets | `.env` outside web root (mode 600); no secrets in source; storage/ and internals denied by `.htaccess`. |
| Installer | One-time setup key + lock file; demo data refused in production. |

## Not implemented (must be addressed before production)
MFA; suspicious-login alerts; password-reset by email; encryption of integration credentials at rest (no live integrations yet);
tamper-evident (hash-chained) audit log; automated dependency/vulnerability scanning; penetration test; WAF/DDoS (host/CDN).

**The database access layer must receive an independent security review before production**, as required by the project brief.

## Compliance review checklist (requires qualified professionals)

| # | Item | Who |
|---|---|---|
| 1 | PCI DSS scope: confirm SAQ type with acquirer once a certified semi-integrated/hosted provider is integrated; keep card data out of scope | QSA / acquirer |
| 2 | Payment provider certification for each processor adapter (Stripe/Square/Clover/NMI/Authorize.Net/PayPal) | Provider |
| 3 | Sales tax: rates, product taxability, exemptions, nexus, filing; consider Avalara/TaxJar | Tax advisor |
| 4 | Privacy: CCPA/CPRA and other state laws, privacy policy, DPA, data retention and deletion | Privacy counsel |
| 5 | Terms of service, acceptable use, SLA, subscription billing terms, auto-renewal disclosures (e.g. CA ARL) | Counsel |
| 6 | Gift card laws (expiration, fees, escheatment) per state | Counsel |
| 7 | EBT/SNAP, age-restricted sales, alcohol/tobacco | Provider + counsel |
| 8 | Tips/service charges, payroll exports, labor/timekeeping (when built) | Employment counsel |
| 9 | Accessibility: WCAG 2.2 AA audit of public, POS and customer-facing pages | Accessibility auditor |
| 10 | Security: code review of `app/core/db.php` and all modules, penetration test, incident response plan | Security firm |
| 11 | Breach notification procedures by state | Counsel |
| 12 | Industry-specific (healthcare/wellness data must not be collected without HIPAA review) | Counsel |
