git-credential-sec: the token goes to https://gitea.dooplex.hu only (R-925)
gates / gates (push) Successful in 3m41s

The helper answered any server git asked about. It now reads protocol and host and answers one server.
Test: scripts/test_git_credential_sec.py (7 cases; red-proofed, 4 fail against the old helper).

Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
This commit is contained in:
admin committed 2026-11-11 15:22:51 +01:00
1 parent d4c7e84c22
commit b79f9e1673
3 files changed
+56

No files matched your search

+15
View File
@@ -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 <command>\n' >&2
printf 'quit=true\n'
+37
View File
@@ -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)