> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.doc-detective.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.doc-detective.com/_mcp/server.

# Protect sign-in secrets and session files

> Store test-account credentials as CI secrets, and keep session files, cookies, and recordings out of Git and uploaded CI artifacts.

A sign-in test handles two kinds of secrets: the credentials it signs in with, and the session it saves. Anyone with either can act as your test account. Doc Detective masks credentials in its output, but it can't mask the session files that it writes for later tests to read. This page covers where to keep each one on your computer and in CI.

## Store credentials as CI secrets

Keep passwords, authenticator setup keys, and API tokens out of your specs. Reference them as `$NAME`, and supply the values from the environment:

* **Locally,** put them in a `.env` file, and add `.env` to `.gitignore`. The CLI loads a `.env` file from the folder you run it in. To load a file from another path, set [`loadVariables`](/docs/actions/loadvariables) in your config. Variables already set in the environment take precedence over both, and a missing file is skipped.
* **In CI,** store them as CI secrets and pass them to the job as environment variables. There's no `.env` file in CI, so Doc Detective reads the job's environment. In GitHub Actions, set `env` on the job:

  **`.github/workflows/doc-detective.yml`**

  ```yaml title=".github/workflows/doc-detective.yml"
  jobs:
    docs-tests:
      runs-on: ubuntu-latest
      env:
        APP_USER: ${{ secrets.APP_USER }}
        APP_PASSWORD: ${{ secrets.APP_PASSWORD }}
        TOTP_SECRET: ${{ secrets.TOTP_SECRET }}
      steps:
        - uses: actions/checkout@v4
        - uses: doc-detective/github-action@v2
  ```

  In other CI systems, expose each secret to the job as an environment variable in the same way.

Agree with your security owner on who rotates each secret, and update the CI secret when it changes. A pull request from a fork usually gets no secrets, so its sign-in tests can't sign in. Run them on branches in your own repository.

Give each repository, or each job that runs at the same time, its own test account. Runs that share an account can sign each other out. Two sign-ins within the same 30 seconds can also get the same one-time code, which many apps accept only once.

### When an agent writes your tests

Give the agent the variable names, such as `APP_USER` and `TOTP_SECRET`, never their values. Don't paste a password or setup key into a prompt, and have the agent reference each secret as `$NAME` in specs.

## What Doc Detective masks

Doc Detective masks the value of every variable a test substitutes as `$NAME`, or loads from a `.env` or `loadVariables` file. Logs, reports, and results show `***NAME***` instead. In the browser:

* A field that a test types a secret into stays hidden for the rest of the page's life. It shows dots, or no text in browsers that can't show dots. Screenshots and recordings show the hidden field.
* Before each screenshot, Doc Detective blurs page text and form fields that show a secret. That includes `screenshot` steps, automatic screenshots, and the screenshots that recording checkpoints take.

For the full rules, and how to show a value that isn't secret, see [Secrets in output](/docs/ci/secrets).

## What masking doesn't hide

* **State and cookie files.** `saveState` and `saveCookie` files hold real session cookies and tokens, because `loadState` and `loadCookie` read them back.
* **Cookies saved to a variable.** A cookie that `saveCookie` saves with `variable` isn't masked until a later step uses it as `$NAME`. Don't print it in `runShell` or `runCode` commands.
* **Recordings.** Between screenshots, a recording shows the page as it is. Typed secrets stay hidden, but page text that shows a secret isn't blurred.
* **Text inside iframes,** shadow DOM, and canvas elements isn't blurred in screenshots or recordings.
* **Native app and device screenshots and recordings** aren't blurred at all.

The sign-in pages show what a signed-in reader sees, which can include an account's name, email address, or API keys. Masking hides only values from your variables. Sign in with a test account whose pages hold nothing private, and set `"autoRecord": false` on the sign-in spec so it isn't recorded.

## Keep session files out of Git

Save state and cookie files to one folder, and ignore it. The sign-in pages in these docs use `.auth/` at the project root:

**`.gitignore`**

```text title=".gitignore"
.env
.auth/
```

Set `directory` on every `saveState` and `saveCookie` step. Without it, the file lands in `outputDir`, beside your reports. `saveState` and `saveCookie` create the file with owner-only permissions.

`.gitignore` also keeps the files out of pull requests that the GitHub Action opens. With `create_pr_on_change`, the action stages every changed file that Git doesn't ignore. To limit it further, set `pr_paths`. See [GitHub Action](/docs/ci/github-action).

## Keep session files out of CI artifacts

An uploaded CI artifact can outlive the session in it, and anyone who can read the workflow run can download it. Upload only the paths you need, such as your reports and the run folder, and never the project root or the `.auth/` folder. This example assumes `outputDir` is the repository root:

**`.github/workflows/doc-detective.yml`**

```yaml title=".github/workflows/doc-detective.yml"
- uses: actions/upload-artifact@v4
  if: always()
  with:
    name: doc-detective-run
    path: |
      junit.xml
      .doc-detective/runs/
    include-hidden-files: true
    retention-days: 7
```

`include-hidden-files: true` uploads the hidden `.doc-detective/` run folder. With it on, a broad path such as `.` would upload `.auth/` and `.env` too. The run folder holds screenshots and recordings of signed-in pages, so keep `retention-days` short. For more on run artifacts, see [Reporters and artifacts](/docs/ci/reporters-and-artifacts).

A hosted CI runner discards its files when the job ends. On a self-hosted or long-lived runner, delete the `.auth/` folder at the end of the job:

**`.github/workflows/doc-detective.yml`**

```yaml title=".github/workflows/doc-detective.yml"
- if: always()
  run: rm -rf .auth
```