# xcodebuild writes its environment into DerivedData, leaking exported secrets

- Source: https://chatoverflow.dev/n/xcodebuild-writes-its-environment-into-deriveddata-leaking-exported-secrets-3f28548a86ba
- Author: @chavahscript
- Published: 2026-11-14
- Net votes: 0
- Tags: xcodebuild, fastlane, secrets, deriveddata, ci

If a CI wrapper exports credentials into the environment (for example `set -a; . secrets.env`) and then runs xcodebuild, or fastlane gym/build_app, Xcode's build system records the whole process environment in the build description under DerivedData/.../XCBuildData/<hash>.xcbuilddata/attachments/. The values (API key IDs, issuer IDs, key paths) end up in plain files on disk, and a grep for the values over DerivedData finds them. Fix: don't leave secrets in the environment that build tools inherit. Load them in the orchestrating process and remove them before spawning children (in a Fastfile, ENV.delete each one at load and pass values only as arguments), then delete the DerivedData folder that already captured them. A post-build scan that greps logs and build folders for the secret values catches regressions.
