diff --git a/.github/check_projects.py b/.github/check_projects.py new file mode 100755 index 0000000..250e202 --- /dev/null +++ b/.github/check_projects.py @@ -0,0 +1,163 @@ +#!/usr/bin/env python3 +"""Checks every pull request to main: the files Allen's visitors build must stay inside their +home, be plain allowlisted text, load nothing from elsewhere and carry no secret or personal data. + +Run by .github/workflows/project-checks.yml from the main branch's copy of this file (the +pull request's copy is used only while main has none), with no token and no secrets: + + check_projects.py BASE_REV PR_REV HEAD_REF + +Rules (kept in step with allen_build.py / allen_spool.py in aien-dev/aienos.com, which apply +them before anything is pushed; this check is the second, independent look): + - projects/// only; handle and project are lowercase names; + files: index.html, README.md, meta.json, name.om|js|css|md|txt|patch; no folders below; + - UTF-8 text, no control characters, at most 64 KiB a file and 12 files a project; + - index.html, .js and .css load or send nothing from elsewhere (no remote script, link, + frame, fetch, WebSocket, beacon, import...); + - nothing shaped like a key, token or password; no email address anywhere and no phone + number in prose or the meta.json title and description (Allen removes them before filing; one here is a leak); + - meta.json is the pusher's: exactly its fields, matching the folder, no personal data; + - every touched project still has README.md, meta.json and index.html or an .om file; + - a branch named u/ or p// (Allen's) changes nothing else. +Exit 0 when every rule holds, 1 with one line per finding otherwise. +""" + +import json +import re +import subprocess +import sys + +HANDLE = r"(?:[a-z](?:[a-z0-9]|-(?=[a-z0-9])){1,23}-[0-9a-f]{8}|anon-[0-9a-f]{10})" +NAME = r"[a-z0-9](?:[a-z0-9-]{0,38}[a-z0-9])?" +PATH = re.compile(r"^projects/(%s)/(%s)/([^/]+)$" % (HANDLE, NAME)) +FILENAME = re.compile(r"^(?:index\.html|README\.md|meta\.json|[a-z0-9][a-z0-9_-]{0,39}\.(?:om|js|css|md|txt|patch))$") +WEB = (".html", ".js", ".css") +PROSE = (".md", ".txt") +MAX_FILE = 64 * 1024 +MAX_FILES = 12 +META = {"v", "handle", "project", "title", "description", "saved", "item", "built_with", "files"} +SECRET = [re.compile(p) for p in ( + r"gh[pousr]_[A-Za-z0-9]{20,}", r"github_pat_[A-Za-z0-9_]{20,}", r"\bsk-[A-Za-z0-9_-]{20,}", + r"\bsk-ant-[A-Za-z0-9_-]{10,}", r"\bAKIA[0-9A-Z]{16}\b", r"\bAIza[0-9A-Za-z_-]{30,}", + r"xox[abprs]-[A-Za-z0-9-]{10,}", r"-----BEGIN [A-Z ]*PRIVATE KEY-----", + r"\beyJ[A-Za-z0-9_-]{10,}\.eyJ[A-Za-z0-9_-]{10,}\.", + r"(?i)\b(api[_-]?key|secret|passw(or)?d|access[_-]?token|auth[_-]?token)\b\s*[:=]\s*['\"]?[^\s'\"]{12,}")] +EXTERNAL = [re.compile(p, re.I) for p in ( + r"]*\bsrc\s*=", r"]*http-equiv", r"\b(src|href|action|formaction|poster|data)\s*=\s*['\"]?\s*(https?:)?//", + r"url\(\s*['\"]?\s*(https?:)?//", r"@import\b", r"\bfetch\s*\(", r"XMLHttpRequest", r"WebSocket", + r"EventSource", r"sendBeacon", r"\bimport\s*\(", r"\bimportScripts\b", r"\bwindow\.open\b")] +EMAIL = re.compile(r"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}") +PHONE = re.compile(r"(? MAX_FILE: + out.append("larger than %d KiB" % (MAX_FILE // 1024)) + try: + text = raw.decode("utf-8") + except UnicodeDecodeError: + return out + ["not UTF-8 text"] + why = bad_text(text) + if why: + out.append("contains " + why) + for pat in SECRET: + if pat.search(text): + out.append("looks like it contains a secret (%s)" % pat.pattern[:30]) + break + if name.endswith(WEB): + for pat in EXTERNAL: + if pat.search(text): + out.append("loads or sends something from elsewhere (%s)" % pat.pattern[:40]) + break + if EMAIL.search(text): + out.append("contains an email address") + if name.endswith(PROSE) and PHONE.search(text): + out.append("contains a phone number") + if name == "meta.json": + try: + m = json.loads(text) + except ValueError: + return out + ["meta.json is not JSON"] + if not isinstance(m, dict) or set(m) != META: + out.append("meta.json fields must be exactly %s" % ", ".join(sorted(META))) + elif m.get("handle") != handle or m.get("project") != project: + out.append("meta.json names another home or project") + elif any(PHONE.search(str(m.get(k, ""))) for k in ("title", "description")): + out.append("meta.json contains a phone number") + return out + + +def main(base, pr, head_ref): + findings = [] + changed = git("diff", "--name-status", "--no-renames", "-z", base, pr).decode().split("\0") + entries = [(changed[i], changed[i + 1]) for i in range(0, len(changed) - 1, 2)] + allen = re.fullmatch(r"u/(%s)|p/(%s)/(%s)" % (HANDLE, HANDLE, NAME), head_ref) + touched = set() + for status, path in entries: + m = PATH.match(path) + if not path.startswith("projects/") or path == "projects/README.md": + if allen: + findings.append("%s: a branch from Allen may only change its own project folder" % path) + elif path.startswith(".github/"): + print("note: %s changes the repository's automation; review it by hand" % path) + continue + if not m: + findings.append("%s: outside projects///" % path) + continue + handle, project, name = m.groups() + if allen and allen.group(2) and (handle, project) != (allen.group(2), allen.group(3)): + findings.append("%s: branch %s may only change projects/%s/%s/" % (path, head_ref, allen.group(2), + allen.group(3))) + if allen and allen.group(1) and handle != allen.group(1): + findings.append("%s: branch %s may only change projects/%s/" % (path, head_ref, allen.group(1))) + touched.add((handle, project)) + if status == "D": + continue + mode = git("ls-tree", pr, "--", path).decode().split(" ", 1)[0] + if mode != "100644": + findings.append("%s: must be a plain file (mode %s)" % (path, mode or "?")) + continue + for f in check_file(path, name, handle, project, git("show", "%s:%s" % (pr, path))): + findings.append("%s: %s" % (path, f)) + for handle, project in sorted(touched): + d = "projects/%s/%s/" % (handle, project) + names = [p[len(d):] for p in git("ls-tree", "-r", "--name-only", pr, "--", d).decode().splitlines()] + if not names: + continue # the project was removed + if any("/" in n for n in names): + findings.append("%s: no folders inside a project" % d) + if len(names) > MAX_FILES + 1: + findings.append("%s: more than %d files" % (d, MAX_FILES)) + for need in ("README.md", "meta.json"): + if need not in names: + findings.append("%s: needs %s" % (d, need)) + if not any(n == "index.html" or n.endswith(".om") for n in names): + findings.append("%s: needs index.html or an .om file" % d) + for f in findings: + print("FAIL " + f) + print("%d changed file(s), %d project(s), %d finding(s)" % (len(entries), len(touched), len(findings))) + return 1 if findings else 0 + + +if __name__ == "__main__": + if len(sys.argv) != 4: + sys.exit(__doc__) + sys.exit(main(*sys.argv[1:])) diff --git a/.github/workflows/project-checks.yml b/.github/workflows/project-checks.yml new file mode 100644 index 0000000..88af79e --- /dev/null +++ b/.github/workflows/project-checks.yml @@ -0,0 +1,36 @@ +# Checks every pull request to main with .github/check_projects.py. +# pull_request only (never pull_request_target): the run gets a read-only token and no +# secrets, and no action is used at all: plain git and python3 from the runner image. +# The checker comes from main, so a pull request cannot loosen the rules it is checked by. +name: project checks +on: + pull_request: + branches: [main] +permissions: + contents: read +concurrency: + group: project-checks-${{ github.event.pull_request.number }} + cancel-in-progress: true +jobs: + check: + runs-on: ubuntu-24.04 + timeout-minutes: 5 + steps: + - name: Check the pull request's files + env: + PR: ${{ github.event.pull_request.number }} + REPO: ${{ github.repository }} + HEAD_REF: ${{ github.head_ref }} + run: | + set -eu + git init -q work && cd work + url="https://github.com/$REPO" + git fetch -q --no-tags --depth=2 "$url" "+refs/pull/$PR/merge:refs/check/pr" + git fetch -q --no-tags --depth=1 "$url" "+refs/heads/main:refs/check/main" + if git cat-file -e refs/check/main:.github/check_projects.py 2>/dev/null; then + git show refs/check/main:.github/check_projects.py > ../check.py + else + echo "main has no checker yet; using this pull request's copy" + git show refs/check/pr:.github/check_projects.py > ../check.py + fi + python3 ../check.py refs/check/pr^1 refs/check/pr "$HEAD_REF" diff --git a/README.md b/README.md index 0c06073..758b877 100644 --- a/README.md +++ b/README.md @@ -2,19 +2,28 @@ Every project anyone builds with Aien at [aienos.com/allen/](https://www.aienos.com/allen/) goes here. -- Each project lives in `projects//`: an `index.html` that runs in the browser, the Omega - source (`.om`), a `README.md` and a `meta.json` (slug, title, description, submission date, - item id; no personal data). -- Aien never publishes anything. A project arrives as a pull request on a `submissions/-` - branch. Drake reviews every project before it goes live; only Drake's merge to `main` publishes it. +- Every builder has a home, `projects//`, and each project lives in + `projects///`: a `README.md` (what it is and who it helps), the source (`index.html` + that runs in the browser, Omega `.om`, `.js`, `.css`, notes), and a `meta.json` written by + Aien's filing service (handle, project, title, description, date, item id, file list; no personal + data). A handle is a chosen name plus a tag tied to the visitor's Aien key (`ada-1a2b3c4d`), or a + one-time `anon-...` handle for anonymous builders; never an email address. +- **Save** commits the project to the builder's branch `u/`, viewable here at once. +- **Publish** opens a pull request from `p//` to `main`. Aien never merges and never + writes `main`; Drake reviews every project and only his merge publishes it ("Built with Aien"). +- Every pull request to `main` runs `project checks` (`.github/workflows/project-checks.yml`): + `pull_request` only, read-only token, no secrets, no third-party actions; the checker comes from + `main` and enforces the file allowlist, size caps, no external loads, and the secret and personal + data scan. - Live projects are served by GitHub Pages from `main` at - `https://aien-dev.github.io/omega-projects/projects//`. + `https://aien-dev.github.io/omega-projects/projects///`. - Issues filed from [aienos.com/allen/](https://www.aienos.com/allen/) arrive here labelled `from-aien` (issues filed before the 2026-10-26 rename carry `from-allen`), with an `area:` label naming the repository they concern, and are transferred to the right repository. - Email addresses and phone numbers are removed before anything is filed. -Pages must be self-contained: no external scripts, stylesheets, frames or network requests. +## Licence -Licensed under the Apache License 2.0 with LLVM Exceptions; see `LICENSE` and `NOTICE`. +Every project stays its author's. By submitting it here the author licences it under +[Apache-2.0](LICENSE). diff --git a/index.html b/index.html index 899b33e..00a6826 100644 --- a/index.html +++ b/index.html @@ -18,7 +18,7 @@ Drake reviews every project before it goes live here.

  • No projects are live yet.
-

Each live project is served at projects/<slug>/ under this address.

+

Each live project is served at projects/<handle>/<project>/ under this address.

Source on GitHub

diff --git a/projects/README.md b/projects/README.md index 605de8c..5ecd65e 100644 --- a/projects/README.md +++ b/projects/README.md @@ -1,7 +1,8 @@ # Projects -One directory per project: `projects//` with `index.html`, `.om`, `README.md` and -`meta.json`. Submissions arrive as pull requests from Aien at https://www.aienos.com/allen/ and go -live only after Drake reviews and merges them. +One home per builder, one directory per project: `projects///` with `README.md`, +`meta.json` and `index.html` or `.om` (plus optional `.js`, `.css`, `.md`, `.txt`, `.patch`). +Saves land on `u/`; published projects arrive as pull requests from `p//` +via Aien at https://www.aienos.com/allen/ and go live only after Drake reviews and merges them. No projects are live yet.