aien-translate
aien-dev/aien-translate
Brought by drakestapleton
aien-translate / AUDIT_SCOPE.md
| 1 | # Audit scope |
| 2 | |
| 3 | Written for an outside, independent security audit. Revision described: |
| 4 | `fc09dfe90e0170e422e44febb6de08c7f0c3a460` on `main`, 2026-10-26. Everything below is taken from the repository's own files at |
| 5 | that revision; items marked NOT_RUN were not executed while writing this document. |
| 6 | |
| 7 | ## What this repository is |
| 8 | |
| 9 | A Rust HTTP server (axum) that implements the translate.js endpoints (`/translate.json`, |
| 10 | `/language.json`, `/connectTest.json`, `/init.json`, `/health`; `/ip.json` is not offered) by |
| 11 | sending text to an OpenAI-style chat model server (`GET /v1/models`, `POST |
| 12 | /v1/chat/completions`). Every translation passes a guard before it is returned, and results are |
| 13 | saved in a SQLite cache. Source: `src/main.rs` (flags), `src/lib.rs` (routes, admission, |
| 14 | 429 lines), `src/engine.rs` (model client, 362), `src/guard.rs` (141), `src/cache.rs` (69), |
| 15 | `src/langs.rs` (31 languages). Python clients in `scripts/` translate a README, a built site, or a |
| 16 | LaTeX paper through a running server. `docs/i18n/README.*.md` are machine translations. Licence |
| 17 | AGPL-3.0-only. |
| 18 | |
| 19 | ## What to review, in priority order |
| 20 | |
| 21 | 1. Admission and authentication in `src/lib.rs`: `Admission::new`, `authorized` (length check |
| 22 | plus `subtle::ConstantTimeEq`), `allow_client` (per-IP quota, `CLIENTS_MAX` 1024), |
| 23 | `DefaultBodyLimit::max(MAX_REQUEST_BYTES)` (16,384), the query length check in `translate_h`, |
| 24 | and which routes require the token (README: `/translate.json` and `/health`). |
| 25 | 2. Token file handling in `src/main.rs`: refused if group or other can access it (`mode & 0o077`), |
| 26 | must be a single line of at least 32 printable ASCII bytes. Without `--auth-token-file` the |
| 27 | loopback server accepts unauthenticated requests; review what any local process or a browser |
| 28 | page that can reach the loopback port (cross-site form `POST`, DNS rebinding) can do in that |
| 29 | mode. |
| 30 | 3. `src/guard.rs`: the rules that decide whether model output is served. Model output is |
| 31 | untrusted; check that HTML or script in a translation cannot reach the page through translate.js. |
| 32 | 4. `src/engine.rs`: batching, one request at a time, reply parsing, and the split-and-retry |
| 33 | fallback when a batch reply cannot be matched to its inputs (`tests/fixtures/` holds recorded |
| 34 | bad replies). |
| 35 | 5. `src/cache.rs`: parameterised `query_row` and `execute`; cache key derivation (sha2); the cache |
| 36 | file holds visitors' page text (AGENTS.md: never commit it). |
| 37 | 6. `params` and `parse_text` in `src/lib.rs`: form, query and JSON text parsing. |
| 38 | 7. Python clients `scripts/translate_site.py`, `scripts/translate_latex.py`, |
| 39 | `scripts/translate_readme.py` and `demo/check.py`: they write translated files to output |
| 40 | directories; check path handling of names taken from input sites and papers. |
| 41 | |
| 42 | ## Trust boundaries |
| 43 | |
| 44 | - Untrusted: HTTP request bodies and query strings; model output; for the scripts, the input site, |
| 45 | README or LaTeX source. |
| 46 | - Trusted: the reverse proxy in front of the server (README sets its duties: visitor |
| 47 | authentication, cross-site rejection, per-visitor rate limiting, request size caps, stripping |
| 48 | client `Authorization`, adding the backend token); the model server named by `--engine`; the |
| 49 | token file. |
| 50 | - Behind a proxy the backend sees only the proxy IP, so native per-IP quotas do not replace proxy |
| 51 | quotas (AGENTS.md). |
| 52 | |
| 53 | ## Threat model summary |
| 54 | |
| 55 | - Assets: the model server's capacity (possibly a shared GPU); the backend token; visitors' page |
| 56 | text in the cache; integrity of the translated page. |
| 57 | - Attackers considered: unauthenticated callers, quota exhaustion, a model reply that drops |
| 58 | structure or does not match its batch. |
| 59 | - Defended: loopback-only listener, optional constant-time token check, size and count limits, |
| 60 | per-IP quota, single active slot with 429, guard with fallback to the original text. |
| 61 | - Not defended / explicitly out of scope: public exposure without the proxy contract; README notes |
| 62 | slow or restarting model requests can hold the single slot for a long time; machine translation |
| 63 | quality is not reviewed (AGENTS.md: published as machine translation). |
| 64 | |
| 65 | ## Build from source at a pin |
| 66 | |
| 67 | Needs a stable Rust toolchain (version not pinned). SQLite is bundled through `rusqlite` 0.32. |
| 68 | `Cargo.lock` committed (169 packages). reqwest 0.12 uses `rustls-tls` with default features off. |
| 69 | |
| 70 | ```sh |
| 71 | cargo build --release |
| 72 | ./target/release/aien-translate --help |
| 73 | ``` |
| 74 | |
| 75 | ## Run every test |
| 76 | |
| 77 | NOT_RUN while writing this document. |
| 78 | |
| 79 | ```sh |
| 80 | cargo test |
| 81 | ``` |
| 82 | |
| 83 | AGENTS.md: unit tests and end-to-end tests against a fake model server, no GPU and no network. |
| 84 | Test attributes at this revision: `src/engine.rs` 9, `src/guard.rs` 7, `src/lib.rs` 3, |
| 85 | `tests/protocol.rs` 13. Expected: `test result: ok` for each target. |
| 86 | |
| 87 | Not runnable without external pieces, NOT_RUN: a real server against a model server; the Python |
| 88 | scripts (need a running server; `translate_site.py` needs beautifulsoup4); `demo/check.py` (needs |
| 89 | Playwright and a downloaded translate.js). |
| 90 | |
| 91 | ## Known limitations and NOT_RUN |
| 92 | |
| 93 | - No tracked CI workflow at this revision. |
| 94 | - The guard and admission behaviour are tested against a fake model only. |
| 95 | - Real proxy deployments are outside the repository. |
| 96 | - `translate_readme.py` has no `--help`; unknown arguments are read as language codes (AGENTS.md). |
| 97 | |
| 98 | ## Dependencies and provenance |
| 99 | |
| 100 | - Direct dependencies: axum 0.8, tokio 1, reqwest 0.12 (rustls-tls), rusqlite 0.32 (bundled), |
| 101 | serde, serde_json, sha2 0.10, regex 1, form_urlencoded 1, subtle 2; dev tokio-stream. |
| 102 | - Python scripts use the system `python3`; beautifulsoup4 and Playwright are optional extras, not |
| 103 | locked. |
| 104 | - translate.js is not vendored; `demo/translate.js` is downloaded and ignored by git. |
| 105 | |
| 106 | ## Evidence |
| 107 | |
| 108 | No receipts are stored in this repository. AGENTS.md asks that pull requests carry the `cargo |
| 109 | test` result in their body. |