interplane.Get Omega
Read in your language

aien-translate

aien-dev/aien-translate

Brought by drakestapleton

GitHub aien-dev/aien-translate#4 (code only)

closed derived 70bb9bccfdf07829 #4

Imported from GitHub aien-dev/aien-translate#4 (code only)

GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed).

Base 7a97bf93eb12d5262cb108bdd1b218a1add2c8e3 · Head 65080ff81c09b8cfd39679f614e65d664d477c13

Fetch it

A git bundle of the pull request's head, 6466 bytes.

curl -fsSL https://interplane.io/drakestapleton/aien-translate/patches/70bb9bccfdf07829.bundle -o 70bb9bccfdf07829.bundle
git fetch 70bb9bccfdf07829.bundle refs/pull/4/head

Raw bundle · Diff

Provenance

This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record:

github-import 1
aien-dev/aien-translate
4
65080ff81c09b8cfd39679f614e65d664d477c13
{"kind":"github-import","owner":"aien-dev","repo":"aien-translate","number":4,"url":"https://github.com/aien-dev/aien-translate/pull/4","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:39:57Z","metadata":"unavailable","state_derived":true}

Changes

diff --git a/.github/dependabot.yml b/.github/dependabot.yml
new file mode 100644
index 0000000..c0337ff
--- /dev/null
+++ b/.github/dependabot.yml
@@ -0,0 +1,14 @@
+# Dependabot: monthly version updates for the pinned GitHub Actions and the Cargo lockfile.
+# Pull requests only; nothing merges itself. Security advisories are handled by GitHub
+# Dependabot security updates on the repository settings.
+version: 2
+updates:
+  - package-ecosystem: github-actions
+    directory: /
+    schedule:
+      interval: monthly
+  - package-ecosystem: cargo
+    directory: /
+    schedule:
+      interval: monthly
+    versioning-strategy: lockfile-only
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 0000000..3af3eb5
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -0,0 +1,37 @@
+# CI: build and test with the committed Cargo.lock (--locked refuses any silent dependency
+# drift) on a GitHub-hosted runner, with pinned actions and read-only token permissions.
+# A second job writes an SPDX SBOM of the tree so auditors can diff what a commit contains.
+name: CI
+on:
+  pull_request:
+  push:
+    branches: [main]
+permissions:
+  contents: read
+jobs:
+  test:
+    runs-on: ubuntu-latest
+    timeout-minutes: 30
+    steps:
+      - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
+        with:
+          persist-credentials: false
+      - uses: dtolnay/rust-toolchain@b725eda525362e7cf34af9a7243cac1e3f01a7ec # stable
+      - name: Toolchain record
+        run: rustc --version && cargo --version
+      - name: Build
+        run: cargo build --locked --all-targets
+      - name: Test
+        run: cargo test --locked
+  sbom:
+    runs-on: ubuntu-latest
+    timeout-minutes: 10
+    steps:
+      - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
+        with:
+          persist-credentials: false
+      - uses: anchore/sbom-action@66cbf4bc1f1c0d2edc94016e65bc221b6bb0ad6c # v0.24.3
+        with:
+          path: .
+          format: spdx-json
+          artifact-name: sbom-${{ github.sha }}.spdx.json
diff --git a/AUDIT_SCOPE.md b/AUDIT_SCOPE.md
new file mode 100644
index 0000000..74059a1
--- /dev/null
+++ b/AUDIT_SCOPE.md
@@ -0,0 +1,109 @@
+# Audit scope
+
+Written for an outside, independent security audit. Revision described:
+`fc09dfe90e0170e422e44febb6de08c7f0c3a460` on `main`, 2026-10-26. Everything below is taken from the repository's own files at
+that revision; items marked NOT_RUN were not executed while writing this document.
+
+## What this repository is
+
+A Rust HTTP server (axum) that implements the translate.js endpoints (`/translate.json`,
+`/language.json`, `/connectTest.json`, `/init.json`, `/health`; `/ip.json` is not offered) by
+sending text to an OpenAI-style chat model server (`GET /v1/models`, `POST
+/v1/chat/completions`). Every translation passes a guard before it is returned, and results are
+saved in a SQLite cache. Source: `src/main.rs` (flags), `src/lib.rs` (routes, admission,
+429 lines), `src/engine.rs` (model client, 362), `src/guard.rs` (141), `src/cache.rs` (69),
+`src/langs.rs` (31 languages). Python clients in `scripts/` translate a README, a built site, or a
+LaTeX paper through a running server. `docs/i18n/README.*.md` are machine translations. Licence
+AGPL-3.0-only.
+
+## What to review, in priority order
+
+1. Admission and authentication in `src/lib.rs`: `Admission::new`, `authorized` (length check
+   plus `subtle::ConstantTimeEq`), `allow_client` (per-IP quota, `CLIENTS_MAX` 1024),
+   `DefaultBodyLimit::max(MAX_REQUEST_BYTES)` (16,384), the query length check in `translate_h`,
+   and which routes require the token (README: `/translate.json` and `/health`).
+2. Token file handling in `src/main.rs`: refused if group or other can access it (`mode & 0o077`),
+   must be a single line of at least 32 printable ASCII bytes. Without `--auth-token-file` the
+   loopback server accepts unauthenticated requests; review what any local process or a browser
+   page that can reach the loopback port (cross-site form `POST`, DNS rebinding) can do in that
+   mode.
+3. `src/guard.rs`: the rules that decide whether model output is served. Model output is
+   untrusted; check that HTML or script in a translation cannot reach the page through translate.js.
+4. `src/engine.rs`: batching, one request at a time, reply parsing, and the split-and-retry
+   fallback when a batch reply cannot be matched to its inputs (`tests/fixtures/` holds recorded
+   bad replies).
+5. `src/cache.rs`: parameterised `query_row` and `execute`; cache key derivation (sha2); the cache
+   file holds visitors' page text (AGENTS.md: never commit it).
+6. `params` and `parse_text` in `src/lib.rs`: form, query and JSON text parsing.
+7. Python clients `scripts/translate_site.py`, `scripts/translate_latex.py`,
+   `scripts/translate_readme.py` and `demo/check.py`: they write translated files to output
+   directories; check path handling of names taken from input sites and papers.
+
+## Trust boundaries
+
+- Untrusted: HTTP request bodies and query strings; model output; for the scripts, the input site,
+  README or LaTeX source.
+- Trusted: the reverse proxy in front of the server (README sets its duties: visitor
+  authentication, cross-site rejection, per-visitor rate limiting, request size caps, stripping
+  client `Authorization`, adding the backend token); the model server named by `--engine`; the
+  token file.
+- Behind a proxy the backend sees only the proxy IP, so native per-IP quotas do not replace proxy
+  quotas (AGENTS.md).
+
+## Threat model summary
+
+- Assets: the model server's capacity (possibly a shared GPU); the backend token; visitors' page
+  text in the cache; integrity of the translated page.
+- Attackers considered: unauthenticated callers, quota exhaustion, a model reply that drops
+  structure or does not match its batch.
+- Defended: loopback-only listener, optional constant-time token check, size and count limits,
+  per-IP quota, single active slot with 429, guard with fallback to the original text.
+- Not defended / explicitly out of scope: public exposure without the proxy contract; README notes
+  slow or restarting model requests can hold the single slot for a long time; machine translation
+  quality is not reviewed (AGENTS.md: published as machine translation).
+
+## Build from source at a pin
+
+Needs a stable Rust toolchain (version not pinned). SQLite is bundled through `rusqlite` 0.32.
+`Cargo.lock` committed (169 packages). reqwest 0.12 uses `rustls-tls` with default features off.
+
+```sh
+cargo build --release
+./target/release/aien-translate --help
+```
+
+## Run every test
+
+NOT_RUN while writing this document.
+
+```sh
+cargo test
+```
+
+AGENTS.md: unit tests and end-to-end tests against a fake model server, no GPU and no network.
+Test attributes at this revision: `src/engine.rs` 9, `src/guard.rs` 7, `src/lib.rs` 3,
+`tests/protocol.rs` 13. Expected: `test result: ok` for each target.
+
+Not runnable without external pieces, NOT_RUN: a real server against a model server; the Python
+scripts (need a running server; `translate_site.py` needs beautifulsoup4); `demo/check.py` (needs
+Playwright and a downloaded translate.js).
+
+## Known limitations and NOT_RUN
+
+- No tracked CI workflow at this revision.
+- The guard and admission behaviour are tested against a fake model only.
+- Real proxy deployments are outside the repository.
+- `translate_readme.py` has no `--help`; unknown arguments are read as language codes (AGENTS.md).
+
+## Dependencies and provenance
+
+- Direct dependencies: axum 0.8, tokio 1, reqwest 0.12 (rustls-tls), rusqlite 0.32 (bundled),
+  serde, serde_json, sha2 0.10, regex 1, form_urlencoded 1, subtle 2; dev tokio-stream.
+- Python scripts use the system `python3`; beautifulsoup4 and Playwright are optional extras, not
+  locked.
+- translate.js is not vendored; `demo/translate.js` is downloaded and ignored by git.
+
+## Evidence
+
+No receipts are stored in this repository. AGENTS.md asks that pull requests carry the `cargo
+test` result in their body.
diff --git a/SECURITY.md b/SECURITY.md
new file mode 100644
index 0000000..e3bfa45
--- /dev/null
+++ b/SECURITY.md
@@ -0,0 +1,58 @@
+# Security policy
+
+## Reporting a vulnerability
+
+Report privately. Do not open a public issue, pull request or discussion about it.
+
+1. GitHub: open this repository's Security tab and choose "Report a vulnerability". This
+   creates a private advisory that only the maintainers can see. If that option is not shown,
+   private vulnerability reporting has not been enabled for this repository yet; use email.
+2. Email: drake@aienos.com with the subject `[aien-translate] security report`.
+
+Include the commit or release you tested, the component (path), steps to reproduce, and what an
+attacker gains. If the report involves a secret, say where it was exposed and do not send the
+secret itself. Encrypted mail is not required; do not post proof-of-concept payloads publicly.
+
+## Response targets
+
+This project has one maintainer; the targets below are best effort and stated honestly.
+
+- Acknowledgement: within 3 working days.
+- Triage and severity: within 7 days of acknowledgement.
+- Fix or mitigation for confirmed issues: aim for 30 days for high and critical, 90 days
+  otherwise, with a status update at least every 14 days until closed.
+- Disclosure: coordinated. An advisory is published with credit (unless you ask otherwise)
+  once the fix is on the default branch. Default embargo 90 days, negotiable.
+
+## Scope
+
+`aien-translate` is a Rust HTTP server that answers the translate.js protocol by sending page text
+to an OpenAI-style chat model server, checks every translation with a guard, and caches results in
+SQLite. `scripts/` and `demo/` hold Python client tools.
+
+In scope:
+
+- A request that reaches the model or cache without the bearer token when `--auth-token-file` is
+  set, or a token comparison that leaks the token.
+- The server listening on a non-loopback address (`src/main.rs` refuses this).
+- A bypass of admission limits in `src/lib.rs`: 16 KiB body, 40 texts and 3,000 characters per
+  request, six translation requests per minute per directly connected IP, 1,024 tracked IPs, one
+  active translation with HTTP 429 instead of queueing.
+- A translation that passes the guard (`src/guard.rs`) while dropping or altering a link, email
+  address, backticked code span, placeholder, keep-list name or inline tag marker, or that carries
+  markup able to run script in the visitor's page.
+- Cache poisoning: one visitor's request causing another visitor to receive attacker-chosen text.
+- SQL injection in `src/cache.rs`.
+
+Out of scope:
+
+- translate.js itself (not in this repository), the model server, the reverse proxy that README
+  requires for public traffic, and the host operating system.
+
+## Supported versions
+
+Only the default branch `main`; there is no release (Cargo version `0.1.0`). Reports against older commits are welcome but fixes land on the default branch only.
+
+## Status
+
+No hosted CI workflow is tracked at this revision. No certification, no bug bounty. See AUDIT_SCOPE.md for what to review and how to build and test it.