Baton

API keys in an API collection in git: where they go, and the doors they still get through

A git-based API collection keeps secret names, not values. What Baton's file format refuses, what it lets through, and a setup that holds with any client.

Moving an API collection into git changes the question. Before, it was "can I read the diff". After, it's "what did I just put into a history I can never fully take back".

People are visibly working around it. An engineer setting up Bruno in VS Code (June 2026) adds the collection file itself to .gitignore, because it "may contain sensitive information such as API tokens". Bruno's own post on managing secrets lists the ways they leak, starting with "Committing .bru environment files with secrets to Git" and "Sharing exported collection files without scrubbing secrets". On the Postman side, the maintainers of the Kingfisher scanner put it bluntly (April 2026): "The secret flag is a UI-masking hint only". The API returns the value in plain text. Back in April 2024 Truffle Security scanned about 40,000 public Postman workspaces, found 1,689 live credentials, and reported that 32% of the environment variables holding a live credential were marked as secret.

We make Baton, an API client that stores requests and environments as YAML in your repository, so this is our problem as much as anyone's. Below is what a Baton environment file actually holds, what its parser refuses, and the part that matters more: three ways a key still ends up in git, which the format doesn't stop.

Three places a value can live

A secret value can sit in the file, in the app's local store, or in the environment of whatever runs the requests on a schedule. Only the first goes into git, and once it's there, it stays in the history.

  • Postman. The Native Git setup guide says to "Keep local environment values in the Postman app, and commit only Shared values to Git", and to use Postman Vault for managed secrets. Its collection export also scans for secrets and offers to move them to the vault before you download the file, though "Export anyway" keeps them in plain text. Environment exports are a different matter: in a 2022 comment under Postman's own announcement of the secret type, a user wrote that exporting an environment showed secret values "as plaintext in .postman_environment.json". We haven't been able to check how current versions behave, so treat that as one user's report.
  • Bruno. Mark a variable as secret and, per its docs, "Only the secret name is written" to the environment file. The value stays in a local encrypted store and isn't included when you export a collection. That's the same model as Baton's.
  • Baton. "Environments name them; the values live in your OS keychain," as the site puts it. Scheduled runs happen on a worker you host, which reads values from environment variables (below).

What a Baton environment file holds

This is a staging environment with one ordinary variable and two secrets, written by @dudko.dev/baton-format, the format's published package:

format: 1
name: staging
variables:
  - name: baseUrl
    value: https://staging.example.com
secrets:
  - apiKey
  - clientSecret

secrets is a list of names, nothing more. Parse that file and write it back, and you get the same bytes.

What the parser refuses

Somebody hand-edits the file and tries to keep the value next to its name. Two obvious shapes:

secrets:
  apiKey: sk_live_abc123
FormatError invalid-field  secrets: must be a list
secrets:
  - name: apiKey
    value: sk_live_abc123
FormatError unknown-field  secrets[0].value: unknown field

Both are rejected outright. There's simply no field in the format where a secret's value could go.

What it doesn't refuse

This is where the format stops helping. It separates names from values. It doesn't look for secrets. Three things go through without complaint:

A value glued onto the name. A secret's name is any string, so this parses fine and the "name" is now apiKey=sk_live_abc123:

secrets:
  - apiKey=sk_live_abc123

A token stored as an ordinary variable. Nothing stops anyone putting a key under variables, and it's written in plain text like any other value:

format: 1
name: staging
variables:
  - name: apiKey
    value: sk_live_abc123

A literal token in a request file. Type the token straight into the request's auth instead of {{apiKey}}, and the request file carries it:

url: "{{baseUrl}}/me"
auth:
  type: bearer
  bearer:
    token: sk_live_abc123

None of these is exotic. The second one is what happens when someone adds a variable in a hurry and forgets to make it a secret. Bruno's blog warns about the same thing in its own best practices: "Avoid hardcoding secrets in environment or request files". Postman at least runs a secret scan when you export a collection. Baton's format has nothing equivalent. That's a gap, and it's why the setup at the end has a scanner in it.

When an AI agent edits the collection

Baton ships an MCP server, @dudko.dev/baton-mcp, so an AI coding agent can edit requests through structured tools rather than raw files. Its README says "A tool call carrying a literal credential is rejected with a message telling the agent to use a {{secret:name}} reference instead."

That holds for some fields, not all of them. In version 0.2.0 we sent a request with a literal value in each place a credential can go:

where the literal value goes what happens
bearer token, basic-auth password, API-key value refused (even hunter2, so it checks the field, not the shape of the value); a {{secret:name}} reference is written
digest password, AWS SigV4 secret key and session token, OAuth 2 client secret written to the file
the URL's query string, a query parameter, an Authorization header, a JSON body written to the file

So the README overstates it. If an agent puts a key in an OAuth 2 client secret or an Authorization header, it goes into the file, and from there into your next commit. Think of the guard as a seatbelt for the three most common fields, not as a scanner.

Scheduled runs

The @dudko.dev/baton-worker README lists BATON_SECRET_<NAME> as the variable that holds "Values for the secret references a request uses". Its example starts the container with -e BATON_SECRET_APITOKEN=<value>.

The values stay out of the repo, then, but they now live wherever that container's environment lives: a compose file, an orchestrator's secret store, a CI variable. Protect that like any other deployment secret, because that's what it is.

A setup that holds, with any of these tools

  1. Names in the repo, values outside it. Baton and Bruno both do this for anything you mark as secret. In Postman, follow its own advice and commit only shared values.
  2. A secret scanner before the commit. The format can't tell sk_live_... from a base URL, but a scanner can. Gitleaks runs as a pre-commit hook and in CI; Kingfisher and TruffleHog are alternatives. This covers the three doors above and the agent fields the guard misses.
  3. Read the first pull request that adds an environment. That's when a token most often goes in as a plain variable, and in a diff it's easy to spot.
  4. Treat the scheduler's environment as production config. Wherever BATON_SECRET_* or its equivalent is set, rotation and access control apply.

If a key has already been committed, rotate it. Rewriting history helps keep it out of future clones, but anyone who pulled before you rewrote still has it.

Reproduce it

Node 24, npm i @dudko.dev/baton-format, then:

// env-file.mjs: what an environment file holds, and what the parser does
// when a value is put where only a name belongs.
import {
  parseEnvironmentFile, serializeEnvironmentFile,
  parseRequestFile, serializeRequestFile,
} from "@dudko.dev/baton-format";

const show = (label, fn) => {
  try {
    const out = fn();
    console.log(`--- ${label}: ACCEPTED`);
    if (out) console.log(out);
  } catch (e) {
    console.log(`--- ${label}: REFUSED  ${e.code ?? ""} ${e.path ?? ""} :: ${e.message}`);
  }
};

// variables with values, secrets by name only
const env = {
  format: 1, name: "staging",
  variables: [{ name: "baseUrl", value: "https://staging.example.com" }],
  secrets: ["apiKey", "clientSecret"],
};
const text = serializeEnvironmentFile(env);
show("environment file", () => text);
show("round trip identical", () =>
  String(serializeEnvironmentFile(parseEnvironmentFile(text)) === text));

// a value next to the secret's name
show("secrets as a map", () => parseEnvironmentFile(
  "format: 1\nname: staging\nvariables: []\nsecrets:\n  apiKey: sk_live_abc123\n"));
show("secret with a value field", () => parseEnvironmentFile(
  "format: 1\nname: staging\nvariables: []\nsecrets:\n  - name: apiKey\n    value: sk_live_abc123\n"));
show("value glued to the name", () => JSON.stringify(parseEnvironmentFile(
  "format: 1\nname: staging\nvariables: []\nsecrets:\n  - apiKey=sk_live_abc123\n").secrets));

// a token as an ordinary variable
show("token as a variable", () => serializeEnvironmentFile(parseEnvironmentFile(
  "format: 1\nname: staging\nvariables:\n  - name: apiKey\n    value: sk_live_abc123\nsecrets: []\n")));

// a token typed into a request's auth
const req = {
  format: 1, id: "01JD0000000000000000000001", name: "Me", method: "GET",
  url: "{{baseUrl}}/me", query: [], headers: [],
  auth: { type: "bearer", bearer: { token: "sk_live_abc123" } },
  body: { type: "none" }, scripts: {}, presets: [], meta: { tags: [] },
};
show("literal bearer token", () =>
  serializeRequestFile(parseRequestFile(serializeRequestFile(req))));

node env-file.mjs prints each case with ACCEPTED or REFUSED. If a later version starts refusing the last three, good, and this article needs an update.

The Baton demo runs in the browser with nothing to install, if you want to see how environments and secrets look from the app side.