Skip to content
Documentation

ARXD security

Rendered from the repository’s own documentation directory.

ARXD security

What is enforced, where it is enforced, and what is knowingly not covered. A security document that lists only strengths is a document nobody should trust, so §8 is as important as the sections above it.


1. Authentication

Passwords are hashed with PASSWORD_ARGON2ID and cost parameters from ARGON_MEMORY and ARGON_TIME. password_needs_rehash() runs on every successful login, so raising the cost migrates users as they sign in rather than requiring a reset. A password is never logged, never emailed, and never returned in any API response.

Sessions are server-side. The cookie is HttpOnly, SameSite=Lax, and Secure when SESSION_SECURE is set — and it is set in production. Session identifiers are regenerated on privilege change, so a fixation attempt does not survive sign-in.

Second factor is TOTP, implemented in Core\Totp. REQUIRE_2FA_FOR_STAFF forces enrolment for platform staff. Losing a device is recoverable by an operator with server access (user:reset-2fa), which is a deliberate choice: the alternative is a customer permanently locked out of their own account.

Login throttling uses LOGIN_MAX_ATTEMPTS over LOGIN_DECAY_SECONDS. It is per-account and per-address, stored in the database because there is no Redis. rate:clear exists for the legitimate lockout, and using it is audited.

API tokens are stored as SHA-256 hashes. The plaintext is shown exactly once at creation. Revocation is immediate because the hash is the lookup key — there is no cached copy to go stale.


2. Authorisation

Core\Rbac holds roles and permissions as data, not as conditionals. A route declares what it needs:

$router->group('can:customer.view', ...);

Three rules follow from that and are enforced in review:

  1. Tenant scope comes from the credential, never from a request parameter.

There is no ?org= that widens a query. A service resolves the organisation from the authenticated user and applies it in SQL.

  1. A missing resource returns 404, not 403, when it exists in another

tenant. 403 would confirm existence and turn the API into an enumeration oracle.

  1. Platform staff are a separate axis from tenant users. platform and

rank: middleware are not satisfied by being an organisation owner.

Denials are recorded through Core\Audit::denied(), so a permission probe leaves a trail even though it changed nothing.


3. Cryptography

| Purpose | Primitive | Where | | --- | --- | --- | | Passwords | Argon2id | Core\Auth | | Reversible secrets (provider tokens) | AES-256-GCM | Core\Crypt | | API token storage | SHA-256 hash | Core\Auth | | Agent artefact signing | RSA-2048, PKCS#1 v1.5, SHA-256 | Core\AgentSigning | | Random material | random_bytes | throughout |

Core\Crypt derives its key from APP_KEY, refuses to operate if the key is missing or short, and stores nonce ‖ tag ‖ ciphertext with a version prefix so the format can change without ambiguity. GCM is authenticated encryption: a modified ciphertext fails to decrypt rather than returning plausible garbage.

The agent signing key is RSA-2048 with the PKCS#1 v1.5 DigestInfo prefix exposed as a constant, because the agent has to reconstruct it byte-for-byte to verify a signature. Agents verify; they never sign. A compromised agent therefore cannot forge an update for another agent.


4. Web security

Content-Security-Policy

Built per request in Core\Application with a fresh nonce:

script-src 'self' 'nonce-…' https://js.stripe.com

There is no unsafe-inline for scripts. The few legitimate inline scripts carry the nonce. This is why the front end is server-rendered with progressive enhancement — a framework that injects script strings would need the directive relaxed, and relaxing it is not on the table.

CSRF

State-changing requests require a token validated by Core\Csrf. The check is middleware, not something each controller remembers to call. JSON API calls authenticated by a bearer token are exempt because a token is not ambient authority — a cross-site form post cannot attach one.

Output encoding

e() escapes on output, everywhere, and is used in every template. Markdown is rendered by Support\Markdown, which escapes the entire input first and then introduces only the tags it recognises. There is no path where raw HTML from a document reaches a browser.

Headers

X-Content-Type-Options: nosniff, Referrer-Policy, X-Frame-Options and HSTS are set for responses the application constructs (in finalise()) and for static responses (in .htaccess). Both paths matter: a header that only exists on PHP-generated responses is missing on every image.


5. Data protection

  • Credential material — provider tokens are encrypted with Core\Crypt

before storage. Plaintext never reaches the database.

  • AI calls — ai_calls records model, tokens, cost and latency. It records

no prompts, no completions and no keys. Usage is billable without becoming a transcript archive.

  • Agent uploads — a compliance scan posts file metadata. There is no

endpoint that accepts file contents, so customer documents do not accumulate on the platform.

  • Backups — the database dump contains password hashes and encrypted

provider tokens. It is treated as being as sensitive as the database itself, because it is.

  • Logs — storage/logs/ is 750. Exception traces can quote request data,

so the directory is not world-readable and is never inside a served path.


6. Agent security

The agent runs on customer machines, so the trust boundary faces the wrong way.

  • Deny-by-default tool policy. A role gets a tool only when ToolPolicy

grants it and the caller's permissions allow it.

  • No shell tool. There is no general-purpose command executor in the agent

tool set. propose_console_command and propose_file_edit return a proposal; a human approves it and the normal code path executes it with its normal checks. This is the difference between an assistant and a remote execution service.

  • Bounded runs. AgentRuntime caps at six rounds. A loop that would run

forever fails visibly instead.

  • Single-use enrolment. An enrolment token is consumed on first use and

expires after ENROLLMENT_TTL.

  • Device credentials are separate. A device credential is rejected on a user

route and a user credential is rejected on an agent route.

  • Signed artefacts. The agent refuses an update whose signature does not

verify against the embedded public key.


7. Audit

audit_logs is append-only in practice: nothing in the application updates or deletes a row. It records actor, actor type, action, resource, and metadata, plus explicit denied events.

What gets audited: authentication outcomes, permission denials, credential creation and revocation, billing state changes, plan changes, agent command dispatch and results, deployment and rollback, settings changes, and every approval decision.

The reason it is a table rather than a log file is that it has to answer questions. "Who changed this plan and when" is a query, not a grep.


8. Known gaps and accepted risks

These are real. They are listed so that nobody discovers them by accident.

  1. .env and storage/ live inside the document root. They are protected by

.htaccess deny rules, which is one configuration mistake away from exposure — a Plesk upgrade that drops AllowOverride, or a new vhost without the rules. The correct fix is to move them above the web root, which requires a Plesk document-root change and a coordinated deploy. It is not done here because doing it wrong takes the site down.

  1. No container isolation for builds. Customer repositories that need

arbitrary npm or build execution cannot be run safely on this host. The deployment engine runs only ARXD's own deterministic builder. This is why "arbitrary build command" is refused in the product rather than merely disabled by a flag — there is nothing to isolate a hostile build from.

  1. No staging environment. Every change is verified against production. The

compensating controls are small commits, pre-deploy backups, and the §7 verification sequence in ARXD_DEPLOYMENT.md.

  1. Rate limiting is per-database-row. It works and it is durable, but under

a distributed flood it becomes a write amplifier against MariaDB. A host-level or edge limit is the right second layer and is not configured here.

  1. PAYPAL_SANDBOX is true in production configuration. While that is

true no real money moves, which is a safety feature rather than a flaw — but it also means the live payment path has not been exercised with real funds. It was deliberately not flipped by this work.

  1. The interactive shell is powerful by design. A compromised device

credential can open one. Mitigations: it is device-only, every command is queued and audited, and the console can end a session — but the blast radius is a shell on that machine, and that is worth stating rather than softening.

  1. **Two orphaned marketing views and the demo seeder still contain managed-IT

copy.** Neither is reachable from the public site (see ARXD_IMPLEMENTATION_STATUS.md §5). They are a code-hygiene debt, not an exposure.


9. Reporting a problem

support@arxd.org. A report about this platform is treated as a defect in the platform, not as an inconvenience.

Rendered from docs/ in the repository and escaped before display. The directory itself is not served.