diff --git a/AGENTS.md b/AGENTS.md index 2a88548..56ce043 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -117,7 +117,7 @@ No CI is configured; no rustfmt.toml/clippy.toml — default `cargo fmt`/`clippy - **Errors**: `anyhow::Result` everywhere in core; no custom error enums. The server converts to `ApiError { status, message }` (`routes.rs`) with helpers `not_found`/`bad_request`/`unauthorized`/`forbidden`; any `anyhow` error maps to 500. - **Async**: Tokio only at the server boundary (`#[tokio::main]`, async handlers, `tokio::spawn` for the 24h session-cleanup task). **Core is synchronous** — blocking `reqwest`, subprocess downloaders, sync `rusqlite`. Keep it that way; don't introduce async into archivr-core. - **State**: Axum `AppState { registry, auth_db_path, login_attempts }` via `State` extractor; middleware stack = `setup_guard` (503 until owner exists) → `login_rate_limit` (5/15min per IP) → `security_headers`. -- **Auth extraction**: `AuthUser` implements `FromRequestParts` — session cookie (`session`) or `Authorization: Bearer` token (stored SHA3-256-hashed). Passwords are Argon2. Read-scope Bearer tokens are limited to GET/HEAD/OPTIONS by `token_scope.rs`. Target-aware admin rules (manage, not self, last owner) go through `guards.rs`; don't re-implement them inline. Keep `file://` capture locators limited to staged uploads (`temp/uploads/`) in the API; the CLI is the only place local paths are read directly. +- **Auth extraction**: `AuthUser` implements `FromRequestParts` — session cookie (`session`) or `Authorization: Bearer` token (stored SHA3-256-hashed). Passwords are Argon2. Read-scope Bearer tokens are limited to GET/HEAD/OPTIONS by `token_scope.rs`. Target-aware admin rules (manage, not self, last owner) go through `guards.rs`; don't re-implement them inline. Keep `file://` capture locators limited to staged uploads (`temp/uploads/`) in the API, and reject bare path locators too (core's `determine_source` treats any existing path as `Source::Local`; the handler checks `capture::locator_is_local_path`). The CLI is the only place local paths are read directly. - **Logging**: `eprintln!` with `info:`/`warn:` prefixes. No `tracing`/`log` — don't add structured logging piecemeal. - **External tools by env var**: `ARCHIVR_YT_DLP`, `ARCHIVR_DENO`, `ARCHIVR_JS_RUNTIME`, `ARCHIVR_CHROME`, `ARCHIVR_SINGLE_FILE`, `ARCHIVR_TWEET_PYTHON`, `ARCHIVR_TWEET_SCRAPER`, `ARCHIVR_STATIC_DIR`, `ARCHIVR_BIND`, `ARCHIVR_FFMPEG`. Local transcription: `ARCHIVR_TRANSCRIBE_ENGINES` (the gate; unset = off), `ARCHIVR_TRANSCRIBE_TIMEOUT` (default 3600s, whole job), `ARCHIVR_WHISPER_BACKEND` (`whisper_cpp`|`script`) / `ARCHIVR_WHISPER_CLI` / `ARCHIVR_WHISPER_MODEL` / `ARCHIVR_WHISPER_LANGUAGES`, `ARCHIVR_PARAKEET_CLI` / `ARCHIVR_PARAKEET_MODEL` / `ARCHIVR_PARAKEET_LANGUAGES`, `ARCHIVR_PHONON2_CLI` / `ARCHIVR_PHONON2_MODEL`. Downloaders shell out to subprocesses; resolve binaries through these vars. Env helpers (`required_env`, `env_or`, `optional_env`, `env_timeout`, `resolve_cli`) live in `env_config.rs`; bounded subprocesses go through `process::run_with_timeout` (yt-dlp calls keep `ytdlp.rs`'s private runner). - **yt-dlp is resolved, not just read**: `ARCHIVR_YT_DLP` (set by the flake wrappers) is only the diff --git a/docs/README.md b/docs/README.md index 961f43e..75f8244 100644 --- a/docs/README.md +++ b/docs/README.md @@ -578,7 +578,7 @@ Deno and exits 0 (the UI shows the Deno outcome as `skipped: …`). Access rules enforced by the server: -- **Local files over the API.** A `file://` capture locator is accepted only for a file staged by an upload (under the archive's `temp/uploads/`); any other `file://` path returns 400. The CLI still reads local paths directly. +- **Local files over the API.** A `file://` capture locator is accepted only for a file staged by an upload (under the archive's `temp/uploads/`); any other `file://` path returns 400, and so does a bare path locator (absolute, or relative to the server's working directory). The CLI still reads local paths directly. - **Read-only tokens.** A Bearer token with `scope: read` gets 403 (`read-only token`) on any method other than GET, HEAD or OPTIONS. Cookie sessions are not affected. Bearer use updates `last_used_at`, at most once per 60 seconds. - **Archive paths.** `GET /api/archives` returns each archive's `archive_path` to admins only. `GET /api/archives/:id/info` returns counts and sizes, never filesystem paths. - **Account guards.** Only an owner may manage an owner or admin account. Nobody can disable or delete their own account, and the last active owner cannot be removed or demoted (409). diff --git a/docs/superpowers/specs/2026-10-08-mcp-api-extensions.md b/docs/superpowers/specs/2026-10-08-mcp-api-extensions.md index d3cb920..ab506d5 100644 --- a/docs/superpowers/specs/2026-10-08-mcp-api-extensions.md +++ b/docs/superpowers/specs/2026-10-08-mcp-api-extensions.md @@ -196,7 +196,7 @@ Behavior changes to endpoints that already exist (R1 owns status/roles, R2 owns 1. `PATCH /api/admin/users/:uid/status`: runs the guard sequence of 0.1 with self-guard and last-owner guard. Disabling oneself -> `409`; disabling the last active owner -> `409`; ADMIN targeting an OWNER/ADMIN -> `403`. `status: "active"` re-enable needs only can-manage. 2. `POST /api/admin/users/:uid/roles` (`{"role_slug": ...}`) and `DELETE /api/admin/users/:uid/roles/:role_slug`: granting or removing `owner` **or** `admin` requires OWNER (`403` otherwise); can-manage applies to the target; unknown role slug -> `404` (currently `500`); removing `owner` from the last active owner -> `409` (currently `500`). -3. `POST /api/archives/:id/captures`: a `file://` locator is accepted **only** if it points at a staged upload previously created through `POST /api/archives/:id/uploads` (under the archive's `temp/uploads/`); any other `file://` locator (e.g. `file:///etc/passwd`) -> `400`. The CLI is unaffected. (`rearchive`, text capture unchanged.) +3. `POST /api/archives/:id/captures`: a `file://` locator is accepted **only** if it points at a staged upload previously created through `POST /api/archives/:id/uploads` (under the archive's `temp/uploads/`); any other `file://` locator (e.g. `file:///etc/passwd`) -> `400`. A bare path locator (absolute, or relative to the server's cwd, e.g. `/etc/hosts`) is refused with `400` as well, because core classifies any existing path as a local file. The CLI is unaffected. (`rearchive`, text capture unchanged.) 4. Bearer auth now calls `touch_token`: `api_tokens.last_used_at` is set on use, throttled so it is written at most once per 60 s per token. Visible in T2/U4. 5. `PATCH /api/auth/me`: `new_password` must be >= 8 characters (`400`), and a successful password change deletes every *other* session of the user (the caller's current session survives). 6. `GET /api/archives` (unauthenticated today): `archive_path` is omitted from each item unless the caller is ADMIN. Items are `{"id", "label"}` for everyone else. (The admin view in the frontend reads `archive_path` as an admin, so it keeps working.) @@ -204,7 +204,7 @@ Behavior changes to endpoints that already exist (R1 owns status/roles, R2 owns 8. Bearer tokens past `expires_at` are rejected: the request is treated as unauthenticated (`401` on endpoints that require auth). (Already enforced in `database::get_user_for_token`; covered by a regression test.) 9. `capture_jobs.created_by` is now recorded (the submitter's `user_uid`) by `capture_handler`, text capture, and rearchive via `database::create_capture_job_as`; other callers keep `create_capture_job` (NULL owner). 10. **Inert instance settings (as implemented).** `public_index_enabled`, `public_entry_content_enabled` and `open_registration_enabled` (column `public_archive_submission_enabled`) are stored and returned by `PATCH` / `GET` instance settings, but no server logic reads them yet. Setting them changes nothing in behavior. Do not document them as enforced until a stream wires them in. -11. **`file://` rule (as implemented).** The check of item 3 lives in the capture handler in `routes.rs`; the regression tests are in `jobs.rs` (`file:///etc/hosts` -> `400`, staged upload -> accepted). +11. **`file://` rule (as implemented).** The check of item 3 lives in the capture handler in `routes.rs`; the bare-path check uses `capture::locator_is_local_path`. Regression tests are in `jobs.rs` (`file:///etc/hosts`, bare `/etc/hosts` and `Cargo.toml` -> `400`, staged upload -> accepted). Out of scope (not proposed): entry metadata edits beyond title, job cancel, server-side entry pagination, frontend/UI updates, admin edit of email/display name.