fix(security): server-authoritative approval gate + auth/session/file hardening
Remediate the HIGH and security-relevant findings from the 2026-07-11 audit. H1 — the per-env approval gate is now server-authoritative. The governing project is resolved from the target node's nearest-claimed ancestor (`governing_env_policy`/`_tree` + `governing_project_id` + `ProjectRepository::get_environments_by_id`), independent of the client-supplied `[project]`. Omitting or spoofing the project block can no longer skip a gate the owning project established; a to-create group resolves its declared parent's chain so a fresh subtree node inherits the gate. Fails closed on any read error. H2 — the API-key prefix slice (`&rest[..8]`) is now the boundary-safe `rest.get(..8)`, so an attacker-supplied multibyte bearer can't panic the request task (unauthenticated per-request DoS). Regression test added. C1 — admin sessions gain an absolute lifetime cap (migration 0070, `PICLOUD_SESSION_ABSOLUTE_TTL_HOURS`, default 30d): `lookup` filters it, `touch` clamps the sliding bump to it, so a continuously-used or stolen-but-warm token self-expires. Mirrors the data-plane app-user cap. C2 — `Cache-Control: no-store` on the login and API-key-mint responses (the two that return a raw credential), so a proxy/CDN/browser cache can't retain it. B8 — file downloads are header-safe: `sanitize_stored_filename` guarantees a valid `HeaderValue` (no panic on a control-char name) and BOTH the per-app and group download paths now set attachment + `X-Content-Type-Options: nosniff` + a restrictive CSP, closing a group-path stored-XSS gap. Also folds in the server-side plan-warning plumbing (`plan_warnings`, `PlanResult::warnings`) and the `app_only_reject` message helper that the CLI plan-preview change builds on, plus operator security notes (reads-open shared- topic SSE; the `--env` label is advisory, not a boundary). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -19,6 +19,7 @@ table: admin_sessions
|
||||
created_at: timestamp with time zone NOT NULL default=now()
|
||||
expires_at: timestamp with time zone NOT NULL
|
||||
last_used_at: timestamp with time zone NOT NULL default=now()
|
||||
absolute_expires_at: timestamp with time zone NOT NULL
|
||||
|
||||
table: admin_users
|
||||
id: uuid NOT NULL default=gen_random_uuid()
|
||||
@@ -474,6 +475,7 @@ indexes on abandoned_executions:
|
||||
idx_abandoned_executions_gc: public.abandoned_executions USING btree (created_at)
|
||||
|
||||
indexes on admin_sessions:
|
||||
admin_sessions_absolute_expiry_idx: public.admin_sessions USING btree (absolute_expires_at)
|
||||
admin_sessions_expiry_idx: public.admin_sessions USING btree (expires_at)
|
||||
admin_sessions_pkey: public.admin_sessions USING btree (token_hash)
|
||||
admin_sessions_user_idx: public.admin_sessions USING btree (user_id)
|
||||
@@ -1035,3 +1037,4 @@ constraints on vars:
|
||||
0067: project environments
|
||||
0068: group dead letters
|
||||
0069: email secret version
|
||||
0070: admin session absolute expiry
|
||||
|
||||
@@ -108,7 +108,7 @@ async fn list_with_owner_and_ancestors_surface_ownership() {
|
||||
#[tokio::test]
|
||||
async fn get_environments_by_slug_returns_persisted_policy() {
|
||||
// §3 M3 hermetic gate: the persisted per-env policy round-trips by project
|
||||
// slug. Backs `ApplyService::effective_env_policy` (the `persisted` half).
|
||||
// slug. Backs `ApplyService::governing_env_policy` (the `governing` half).
|
||||
let Some(pool) = pool_or_skip().await else {
|
||||
return;
|
||||
};
|
||||
@@ -147,4 +147,15 @@ async fn get_environments_by_slug_returns_persisted_policy() {
|
||||
.await
|
||||
.expect("get_environments_by_slug");
|
||||
assert!(empty.is_empty());
|
||||
|
||||
// Audit 2026-07-11 H1: the gate now loads the policy by the SERVER-resolved
|
||||
// project id (from the node's ownership walk), not the client slug. The
|
||||
// by-id read must return the same persisted policy as the by-slug read.
|
||||
let by_id = projects
|
||||
.get_environments_by_id(proj_id.into())
|
||||
.await
|
||||
.expect("get_environments_by_id");
|
||||
assert_eq!(by_id.get("production"), Some(&true));
|
||||
assert_eq!(by_id.get("staging"), Some(&false));
|
||||
assert_eq!(by_id.len(), 2);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user