ci: add security checks and commitlint on every push

Security workflow, on every push, pull request and weekly:
- invariants: no npm packages, no child_process/vm/eval in the server,
  no web address outside .github/allowed-hosts.json in the server or in
  the SWFs players load, no committed keys, all JavaScript parses
- secrets: TruffleHog over the pushed commits
- codeql: security-extended queries for the JavaScript and the workflows

Commit messages are checked against Conventional Commits; the commits
publish-public.sh makes are exempt. Actions are pinned to commit SHAs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
SnipzilandClaude Opus 5.5 committed 2026-10-16 18:18:27 -04:00
1 parent 9d50e0a6fd
commit dc38a49749
6 files changed
+329

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
{
"server": [
"ajcontent.akamaized.net",
"burrow.moe",
"challenges.cloudflare.com",
"play.burrow.moe",
"www.cloudflare.com",
"www.w3.org"
],
"swf": [
"academy.animaljam.com",
"adobe.com",
"buddy.animaljam.com",
"crypto.hurlant.com",
"dailyexplorer.animaljam.com",
"dev-content.animaljam.com",
"jump.animaljam.com",
"ns.adobe.com",
"purl.org",
"shop.animaljam.com",
"ssl.google-analytics.com",
"wac.6a16.edgecastcdn.net",
"www.adobe.com",
"www.animaljam.com",
"www.google-analytics.com",
"www.osmf.org",
"www.w3.org"
]
}
+15
View File
@@ -0,0 +1,15 @@
// commit messages follow Conventional Commits ("fix(trades): keep offers
// after a rename"), checked by .github/workflows/commitlint.yml.
//
// the commits the private repository's tools/publish-public.sh makes ("Brought
// up to date with the private repository (abc1234)") are left alone: they are
// written by a script and carry no change of their own to describe.
export default {
extends: ["@commitlint/config-conventional"],
ignores: [message => /^Brought up to date with the private repository \([0-9a-f]+\)/.test(message)],
rules: {
// long links and file paths in a body or footer are fine
"body-max-line-length": [0],
"footer-max-line-length": [0],
},
};
+91
View File
@@ -0,0 +1,91 @@
#!/usr/bin/env node
"use strict";
// what the security audit of 2026-10-16 found true of this server, checked on
// every push so that it stays true (or is changed on purpose):
//
// - it uses no npm packages, so there is no supply chain to break into
// - the server code starts no other programs and runs no generated code
// - the server code names no web address outside .github/allowed-hosts.json
// - no private key, certificate key or .env file is committed
// - every JavaScript file parses
//
// a check that fails says what to do. run it from the repository's root:
//
// node .github/scripts/invariants.js
const fs = require("fs");
const path = require("path");
const {execFileSync} = require("child_process");
const tracked = execFileSync("git", ["ls-files", "-z"], {encoding: "utf8"}).split("\0").filter(Boolean);
const problems = [];
const fail = (file, message) => problems.push({file, message});
// no npm packages
const pkg = JSON.parse(fs.readFileSync("package.json", "utf8"));
for (const field of ["dependencies", "devDependencies", "optionalDependencies", "peerDependencies", "bundledDependencies"]) {
if (pkg[field] && Object.keys(pkg[field]).length) {
fail("package.json", `${field} is not empty. The server has no npm packages on purpose; if one is really needed, change this check in the same pull request and say why.`);
}
}
for (const lock of ["package-lock.json", "yarn.lock", "pnpm-lock.yaml"]) {
if (tracked.includes(lock)) {
fail(lock, "a lockfile means npm packages; see package.json above.");
}
}
// the server's own code: what the game server runs
const serverCode = tracked.filter(file => /^(server|config)\.js$/.test(file) || /^lib\/.*\.js$/.test(file));
const FORBIDDEN = [
[/require\(\s*["'](?:node:)?child_process["']\s*\)/, "starts other programs (child_process)"],
[/require\(\s*["'](?:node:)?vm["']\s*\)/, "runs generated code (vm)"],
[/(?<![\w.$])eval\s*\(/, "runs generated code (eval)"],
[/\bnew\s+Function\s*\(/, "runs generated code (new Function)"],
[/\bprocess\.binding\s*\(/, "reaches into Node's internals (process.binding)"],
];
const allowed = JSON.parse(fs.readFileSync(".github/allowed-hosts.json", "utf8"));
const HOST = /https?:\/\/([A-Za-z0-9.-]+)/g;
for (const file of serverCode) {
const text = fs.readFileSync(file, "utf8");
for (const [pattern, what] of FORBIDDEN) {
if (pattern.test(text)) {
fail(file, `${what}. The server code never did; if this is meant, change this check in the same pull request and say why.`);
}
}
}
// web addresses in the server code and the pages it serves
for (const file of tracked.filter(name => /^(server\.js|config\.js|lib\/.*\.(js|json)|public\/.*\.(html|js))$/.test(name))) {
for (const [, host] of fs.readFileSync(file, "utf8").matchAll(HOST)) {
const name = host.toLowerCase();
if (!allowed.server.includes(name)) {
fail(file, `names ${name}, which is not in .github/allowed-hosts.json ("server"). Add it there if it is meant.`);
}
}
}
// keys and secrets
for (const file of tracked) {
const base = path.basename(file);
if (/\.(pem|key|p12|pfx)$/i.test(base) || /^\.env(\..*)?$/.test(base) || /^id_(rsa|ed25519|ecdsa)$/.test(base)) {
fail(file, "looks like a key or a secrets file. Remove it from the repository (and from its history), and replace the key.");
}
}
// every JavaScript file parses
for (const file of tracked.filter(name => /\.(c|m)?js$/.test(name) && !name.startsWith("tools/decompiled/"))) {
try {
execFileSync(process.execPath, ["--check", file], {stdio: "pipe"});
}
catch (err) {
fail(file, `does not parse: ${String(err.stderr).trim().split("\n").slice(0, 4).join(" ")}`);
}
}
if (problems.length) {
for (const {file, message} of problems) {
console.log(`::error file=${file}::${file} ${message}`);
}
process.exit(1);
}
console.log(`${serverCode.length} server files and ${tracked.length} tracked files checked: no packages, no program starts or generated code, no unlisted hosts, no keys, everything parses`);
+66
View File
@@ -0,0 +1,66 @@
# every web address a SWF players load could reach out to, checked against
# .github/allowed-hosts.json ("swf"). the game files are what the client runs,
# so a host that shows up in one of them for the first time fails the check
# until somebody looks at it and adds it to the list.
#
# python3 .github/scripts/swf-hosts.py [--list] <file.swf> ...
#
# --list prints the hosts found instead of checking them.
import json
import lzma
import re
import sys
import zlib
from pathlib import Path
HOST = re.compile(rb"https?://([A-Za-z0-9.-]+)")
def body(data):
"""the SWF's bytes after the 8-byte header, uncompressed."""
kind = data[:3]
if kind == b"FWS":
return data[8:]
if kind == b"CWS":
return zlib.decompress(data[8:])
if kind == b"ZWS":
# sig(3) version(1) length(4) lzma length(4) props(5) data: rebuilt as
# an .lzma stream of unknown size
return lzma.LZMADecompressor(lzma.FORMAT_ALONE).decompress(data[12:17] + bytes([0xFF] * 8) + data[17:])
raise ValueError("not a SWF")
def hosts(path):
found = set()
for match in HOST.finditer(body(path.read_bytes())):
host = match.group(1).decode("ascii").lower().strip(".-")
if "." in host:
found.add(host)
return found
def main(args):
listing = "--list" in args
files = [Path(arg) for arg in args if arg != "--list"]
allowed = set(json.loads(Path(".github/allowed-hosts.json").read_text())["swf"]) if not listing else set()
failed = False
for path in files:
try:
found = hosts(path)
except (ValueError, lzma.LZMAError, zlib.error) as err:
print(f"::error file={path}::cannot read {path}: {err}")
failed = True
continue
if listing:
print(f"{path}: {', '.join(sorted(found)) or '(none)'}")
continue
for host in sorted(found - allowed):
print(f"::error file={path}::{path} names {host}, which is not in .github/allowed-hosts.json")
failed = True
if not listing and not failed:
print(f"{len(files)} SWFs checked: every web address in them is on the list")
return 1 if failed else 0
sys.exit(main(sys.argv[1:]))
+49
View File
@@ -0,0 +1,49 @@
name: Commit messages
# every commit pushed, and every commit in a pull request, is checked against
# .github/commitlint.config.mjs (Conventional Commits).
on:
push:
pull_request:
permissions:
contents: read
jobs:
commitlint:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
persist-credentials: false
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: 22
# installed for this run only: the server itself has no npm packages
- name: Install commitlint
run: npm install --no-save --no-package-lock --ignore-scripts @commitlint/[email protected] @commitlint/[email protected]
- name: Check the commits
env:
EVENT: ${{ github.event_name }}
PR_BASE: ${{ github.event.pull_request.base.sha }}
PR_HEAD: ${{ github.event.pull_request.head.sha }}
PUSH_BEFORE: ${{ github.event.before }}
PUSH_AFTER: ${{ github.sha }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
run: |
if [ "$EVENT" = pull_request ]; then
from=$PR_BASE to=$PR_HEAD
elif [ -n "$PUSH_BEFORE" ] && [ "$PUSH_BEFORE" != 0000000000000000000000000000000000000000 ] && git cat-file -e "$PUSH_BEFORE^{commit}" 2>/dev/null; then
from=$PUSH_BEFORE to=$PUSH_AFTER
else
# a new branch (or a force push): what it has that the default branch has not,
# or else the last commit alone
from=$(git merge-base "origin/$DEFAULT_BRANCH" "$PUSH_AFTER" 2>/dev/null || true)
[ -n "$from" ] && [ "$from" != "$PUSH_AFTER" ] || from=$PUSH_AFTER~1
to=$PUSH_AFTER
fi
git cat-file -e "$from^{commit}" 2>/dev/null || { npx --no-install commitlint --config .github/commitlint.config.mjs --last --verbose; exit; }
npx --no-install commitlint --config .github/commitlint.config.mjs --from "$from" --to "$to" --verbose
+79
View File
@@ -0,0 +1,79 @@
name: Security
# on every push and pull request, and once a week for newly published CodeQL
# queries:
# - invariants: what the 2026-10-16 security audit found true stays true
# (no npm packages, no program starts or eval in the server, no unlisted
# web addresses in the server or in the SWFs players load, no keys, all
# JavaScript parses). see .github/scripts/.
# - secrets: TruffleHog over the commits pushed
# - codeql: GitHub's code scanning of the JavaScript and of these workflows
on:
push:
pull_request:
schedule:
- cron: "17 4 * * 1"
workflow_dispatch:
permissions:
contents: read
jobs:
invariants:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: 22
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
with:
python-version: "3.12"
- name: Server code
run: node .github/scripts/invariants.js
- name: Game files players load
run: git ls-files -z 'swf/*.swf' | xargs -0 python3 -I .github/scripts/swf-hosts.py
secrets:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
persist-credentials: false
- uses: trufflesecurity/trufflehog@4dd8831c5f12599465d4d45c3c447b4018a34c85 # v3.97.9
with:
version: 3.97.9
extra_args: --results=verified,unknown
codeql:
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: read
security-events: write
actions: read
strategy:
fail-fast: false
matrix:
language: [javascript-typescript, actions]
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
- uses: github/codeql-action/init@2892aa5e19bbd11bc0cff5427e3b750a04d9e3c2 # v4.38.2
with:
languages: ${{ matrix.language }}
queries: security-extended
config: |
paths-ignore:
- tools/decompiled
- swf-src
- uses: github/codeql-action/analyze@2892aa5e19bbd11bc0cff5427e3b750a04d9e3c2 # v4.38.2
with:
category: /language:${{ matrix.language }}