Keep secrets out of API test reports and CI logs
CI logs are read by more people than you think, and kept longer than you'd like. A token printed once in a job log is in every copy of that log, in artifacts, and sometimes in a chat message someone pasted it into. API tests are a common source, because they handle real credentials and print responses.
What's masked for you
In the terminal, the JUnit and HTML reports, the JSON report and saved runs:
- values of secret environment variables,
- values fetched from AWS Secrets Manager, Azure Key Vault or Google Cloud Secret Manager,
- values from
--env-fileand--env-var, Authorization,Cookieand API key headers, wherever the value came from,- cookie values in the cookie jar listing.
A masked value shows as ••••••.
What isn't, and what to do about it
Values passed with --var
--var is for ordinary values like userId=42. A secret passed with --var apiKey=$API_KEY isn't known to be secret. Use --env-var instead, which reads it from the process environment and masks it:
# Not this
requestarium run-collection "Orders API" --env Staging --var apiKey="$API_KEY"
# This
requestarium run-collection "Orders API" --env Staging --env-var apiKey=API_KEYThe same goes for variables in an environment: mark anything sensitive as secret, so it's masked everywhere, not only encrypted.
Response bodies
A login response contains a token. A "get API key" response contains a key. The CLI prints response bodies as received in --verbose output and in the JSON report, and saved runs keep the bodies of failed requests (cut to 2,000 characters).
- Don't run with
--verbosein CI unless you're debugging, and remove it afterwards. - Treat the JSON report (
--out report.json) as sensitive: don't upload it as a public artifact. - In tests, assert on a token without printing it:
pm.expect(body.accessToken).to.be.a('string'), notconsole.log(body).
Script output
console.log output goes into the verbose log and the JSON report. Logging a whole response, or a variable that holds a token, puts it there:
// Avoid
console.log(pm.response.json());
console.log('token', pm.environment.get('accessToken'));
// Better
console.log('login ok, token length', pm.environment.get('accessToken').length);Tokens your scripts fetch
A token saved by a login request's script is a normal variable unless you say otherwise. It's passed to later requests, where it's masked as an Authorization header, but its value may still appear in a body or a log you print. Keep login responses out of logs, and keep the token's lifetime short.
Request bodies
A request that sends a password in its JSON body sends it as written. Use {{password}} from a secret variable, never a literal, so the report shows the masked value.
On the CI side
- Mark CI variables masked (GitLab) or keep them as secrets (GitHub), so the CI masks them too, in case something slips past.
- Don't run untrusted pull requests from forks with secrets. GitHub Actions doesn't give secrets to fork PRs by default; keep it that way.
- Set short retention on artifacts that hold reports.
If a secret did leak into a log
Rotate it first, then clean up: delete the job log or artifact, and check where it was copied. See rotate the secrets your API tests use.