diff --git a/REPORT-golden-token-clock-certpin-2026-11-11.md b/REPORT-golden-token-clock-certpin-2026-11-11.md index 68a2e96a..1f7086aa 100644 --- a/REPORT-golden-token-clock-certpin-2026-11-11.md +++ b/REPORT-golden-token-clock-certpin-2026-11-11.md @@ -53,6 +53,10 @@ through the global `store` helper. **Proposal, nothing changed:** (1) give each (2) put the `github.com` login into the store under its own name; (3) the operator then unsets the global helper and removes the file. Step 3 is the operator's, because it removes a credential. +**Found by the commit's security review and fixed in a second commit:** the helper gave the token to any server git +asked about. It now answers only `https://gitea.dooplex.hu`. `scripts/test_git_credential_sec.py` pins it (7 cases; +4 of them fail against the first version). + No token was made, rotated or deleted. A side effect, filed: `sec put` can no longer push the store by itself (R-1390); the second command is in `STATUS.md`. diff --git a/scripts/git-credential-sec.sh b/scripts/git-credential-sec.sh index 5710e1d8..bff61dae 100755 --- a/scripts/git-credential-sec.sh +++ b/scripts/git-credential-sec.sh @@ -15,6 +15,21 @@ # clear-text credentials file). A public repository still fetches, because the server asks for nothing. # The helper writes the value only to git's pipe: never to a file, the terminal or a log. [ "${1:-}" = get ] || exit 0 +# The token goes to ONE server only. Git writes "protocol=" and "host=" lines on the helper's input; for any other +# server (a submodule, a redirect, a changed address) the helper says nothing and stops git from asking on. +proto=; host= +while IFS= read -r line; do + case "$line" in + protocol=*) proto=${line#protocol=} ;; + host=*) host=${line#host=} ;; + "") break ;; + esac +done +if [ "$proto" != https ] || [ "$host" != gitea.dooplex.hu ]; then + printf 'git-credential-sec: no credential for this server (only https://gitea.dooplex.hu)\n' >&2 + printf 'quit=true\n' + exit 0 +fi if [ -z "${GITEA_GIT_TOKEN:-}" ]; then printf 'git-credential-sec: no token in the environment. Run: sec run GITEA_GIT_TOKEN -- git \n' >&2 printf 'quit=true\n' diff --git a/scripts/test_git_credential_sec.py b/scripts/test_git_credential_sec.py new file mode 100644 index 00000000..7cf36d29 --- /dev/null +++ b/scripts/test_git_credential_sec.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 +"""Pins scripts/git-credential-sec.sh: the token goes to https://gitea.dooplex.hu and to no other server.""" +import os, subprocess, sys + +HELPER = os.path.join(os.path.dirname(os.path.abspath(__file__)), "git-credential-sec.sh") +VALUE = "dummy-value-not-a-secret" + + +def ask(proto, host, token=VALUE, verb="get"): + env = {"PATH": os.environ.get("PATH", "/usr/bin:/bin")} + if token is not None: + env["GITEA_GIT_TOKEN"] = token + p = subprocess.run(["sh", HELPER, verb], input=f"protocol={proto}\nhost={host}\n\n", text=True, + capture_output=True, env=env, timeout=10) + return p.stdout, p.stderr + + +CASES = [ # (name, proto, host, token, verb, gives the value?) + ("the right server gets the value", "https", "gitea.dooplex.hu", VALUE, "get", True), + ("another host gets nothing", "https", "evil.example", VALUE, "get", False), + ("a look-alike host gets nothing", "https", "gitea.dooplex.hu.evil.example", VALUE, "get", False), + ("the right host on a port gets nothing", "https", "gitea.dooplex.hu:8443", VALUE, "get", False), + ("plain http gets nothing", "http", "gitea.dooplex.hu", VALUE, "get", False), + ("no token in the environment gives nothing", "https", "gitea.dooplex.hu", None, "get", False), + ("store is not answered", "https", "gitea.dooplex.hu", VALUE, "store", False), +] + +bad = 0 +for name, proto, host, token, verb, want in CASES: + out, err = ask(proto, host, token, verb) + got = VALUE in out + leak = VALUE in err + ok = got == want and not leak and (want or verb != "get" or "quit=true" in out) + print(("ok " if ok else "FAIL ") + name) + bad += 0 if ok else 1 +print(f"git-credential-sec: {len(CASES) - bad} of {len(CASES)} passed") +sys.exit(1 if bad else 0)