How would you test that untrusted pull-request code cannot steal CI secrets?
Answer
Map which workflows execute contributor-controlled code and ensure they receive no production credentials or privileged write tokens. Use disposable test credentials, protected environments and explicit approval for trusted stages; test attempts to print environment values, modify artifacts, poison caches and exfiltrate over the network. Masking logs is defense in depth, not a substitute for withholding the secret.
Strong answer includes
- separates untrusted execution from privileged credentials
- tests cache, artifact, log and network exfiltration paths
- uses short-lived scoped credentials and protected promotion
Practical example
A pull request from a fork adds a build step that echoes every environment variable to the build log; because the workflow that runs on fork pull requests never has production secrets injected into it in the first place, the exfiltration attempt only exposes a harmless disposable test token, which is exactly the outcome the pipeline design should guarantee before anyone even needs to notice the suspicious echo command.