Skip to content

fix(cli): Keep the React Native wizard's auth token out of committed sentry.properties - #2829

Merged
antonis merged 3 commits into
mainfrom
fix/rn-wizard-auth-token-dotenv
Dec 3, 2026
Merged

antonis merged 3 commits into
mainfrom
fix/rn-wizard-auth-token-dotenv

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Reported as a security issue in getsentry/sentry-react-native#7166. sentry wizard reactNative wrote the auth token to ios/sentry.properties and android/sentry.properties without gitignoring them. They have to stay committed, because CI builds read the org, project and URL from them, so the token got committed too. @sentry/wizard behaves the same. The same steps run for Expo projects whose native folders are committed. The .sentryclirc part of the report was already fixed by #2571.

Which SDK versions read .env.sentry-build-plugin

getsentry/sentry-react-native#4281 shipped in 6.3.0 and made all three upload paths point sentry-cli at $reactRoot/.env.sentry-build-plugin through SENTRY_DOTENV_PATH: scripts/sentry-xcode.sh, scripts/sentry-xcode-debug-files.sh, and the Groovy sentry.gradle. 6.2.0 has none of them. getsentry/sentry-react-native#6119 (8.14.0) only ported sentry.gradle to sentry.gradle.kts and kept that line. So the cutoff is 6.3.0, not 8.14.0. The wizard already requires 6.12.0 or later, so every supported SDK takes the new path. The older path only runs when the SDK version is unknown, or when the user chose to continue on an unsupported version. The auth.token/SENTRY_AUTH_TOKEN check in sentry.gradle only runs with flavorAware, which the wizard doesn't set.

What the wizard does now

  • SDK 6.3.0 or later: writes SENTRY_AUTH_TOKEN with the existing addDotEnvSentryBuildPluginFile, which also gitignores .env.sentry-build-plugin. Both sentry.properties files get only defaults.org, defaults.project and, on self-hosted, defaults.url, and stay committed. CliSetupConfigContent.authToken is now optional, and addSentryCliConfig already skipped the token line without one. It no longer prints "DO NOT commit auth token" when it wrote no token. A message says where the token went, that it's gitignored, and to set SENTRY_AUTH_TOKEN in CI, with the org's auth token settings URL. CI doesn't need SENTRY_URL, since defaults.url stays in the committed files (on SaaS, sentry-cli's default URL is used).
  • Older or unknown SDK: behaves as before (the token stays in sentry.properties), and warns that the files hold the token and are committed. It suggests upgrading the SDK or switching to SENTRY_AUTH_TOKEN.
  • Existing auth.token: when a sentry.properties already has an auth.token line, the wizard leaves it alone. It warns that the file may already be committed with the token, says to remove the line, and says to rotate the token if it was pushed.
  • Expo: addExpoEnvLocal (.env.local) is unchanged.
  • Placeholder token: when the wizard couldn't create a token and .env.sentry-build-plugin ends up with the placeholder, it warns that Release builds fail at the Sentry upload until the placeholder is replaced, and shows the token settings URL, as the Android wizard does.
  • Telemetry: a new tag, auth-token-location, is set to .env.sentry-build-plugin or sentry.properties. auth-token-placeholder records whether the dotenv file holds the placeholder.

The sentry wizard docs fragment gets a React Native paragraph next to the Android one.

This stays a draft until the author decides it's ready.

via Antonis Lilis.

--

View Session [Sentry]

…sentry.properties

The React Native wizard wrote the auth token to ios/ and
android/sentry.properties, which stay committed because builds read the
org and project from them. With @sentry/react-native 6.3.0 or later,
whose iOS build scripts and sentry.gradle read .env.sentry-build-plugin,
the token now goes to that gitignored file, and sentry.properties gets
only the org, project and, on self-hosted Sentry, URL. Older or unknown
SDK versions keep the token in sentry.properties, with a warning.

Co-Authored-By: Antonis Lilis <antonis.lilis@sentry.io>
@vercel

vercel Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cli Ready Ready Preview Dec 3, 2026 9:49am UTC
1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Dec 3, 2026 9:49am UTC

Request Review

@antonis antonis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the wizard couldn't create a token, authToken is the placeholder (DUMMY_AUTH_TOKEN in utils/project-data.ts), so addDotEnvSentryBuildPluginFile writes the placeholder into .env.sentry-build-plugin. The message then still says "The wizard put the auth token in .env.sentry-build-plugin", and Release builds fail at the upload until the placeholder is replaced. The generic warning from createAuthToken doesn't name this file.

Please handle that case like the Android wizard does (#2806): when the token written is the placeholder, say that .env.sentry-build-plugin holds a placeholder, that Release builds fail at the Sentry upload until it's replaced, and show the token settings URL. Add a test.

When the wizard could not create an auth token, the React Native wizard
wrote the placeholder to .env.sentry-build-plugin and still said it put
the auth token there. Like the Android wizard, warn that the file holds a
placeholder, that Release builds fail at the Sentry upload until it is
replaced, and show the token settings URL. Tag auth-token-placeholder.
@vercel
vercel Bot temporarily deployed to Preview – sentry-local December 3, 2026 09:04 Inactive
@sentry-junior

sentry-junior Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

@antonis Good catch, fixed in 1aa2925a. Like the Android wizard, it checks what .env.sentry-build-plugin ends up holding, since the helper keeps a token that's already there. When that's the placeholder, the wizard now warns that the file holds "_YOUR_SENTRY_AUTH_TOKEN_" and that Release builds fail at the Sentry upload until it's replaced, and shows the token settings URL. That warning replaces the "put the auth token in" message. It also sets the auth-token-placeholder tag. There are tests for the placeholder case and for a real token that's already in the file.

@antonis antonis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nine new tests in packages/cli/test/lib/wizard/react-native/patch-native-files.test.ts fail on macOS, though they pass in CI on Linux:

Error: [vitest] No "select" export is defined on the "@clack/prompts" mock. Did you forget to return it from "vi.mock"?

patchXcodeFiles asks "Do you want to run pod install now?" only when platform() === "darwin" (react-native-wizard.ts, around line 445), through confirmPodInstall, which calls clack.select. On Linux the question never comes up. On a Mac it does, and the tests' @clack/prompts mock has no select.

Please make the tests independent of the host OS: mock platform() from node:os, or answer the pod install question in the mock (a select that answers no), so they pass the same way on macOS and Linux. Then run them on macOS, or with platform() mocked to "darwin", to confirm.

… every host

patchXcodeFiles asks whether to run `pod install` only on macOS, and the
tests' @clack/prompts mock had no `select`, so they failed there. Mock
`platform()` to "darwin" and answer the prompt with no, so the tests take
the same path on macOS and Linux.
@vercel
vercel Bot temporarily deployed to Preview – sentry-local December 3, 2026 09:48 Inactive
@sentry-junior

sentry-junior Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

@antonis Fixed in 93ab4eb2. The test file now mocks platform() from node:os to return "darwin", and its @clack/prompts mock has a select that answers no (plus isCancel/cancel for abortIfCancelled). So patchXcodeFiles asks the pod install question on every host, the same way it does on macOS. The first test now asserts continue-with-pod-install is false, which only gets set once that prompt runs, so it proves the macOS path ran. All 203 React Native wizard tests pass here on Linux with that mock in place.

@antonis

antonis commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Tested end to end. Build: main f17f9bb with this PR at 1aa2925 merged locally, packed. Xcode 27.2, JDK 17, sentry-sdks/sentry-react-native, an iPhone 16 simulator and a Pixel 8 emulator. Apps:

  • a fresh bare React Native 0.88.1 app with CocoaPods (--skip-spm);
  • a fresh Expo 58.1.1 app.

To keep the token from coming from anywhere else, builds ran with SENTRY_AUTH_TOKEN unset and HOME pointed at an empty folder, so sentry-cli couldn't fall back to the machine's ~/.sentryclirc.

Check Result
Files after the wizard (bare) ✅ .env.sentry-build-plugin has SENTRY_AUTH_TOKEN and is gitignored. ios/ and android/sentry.properties have only defaults.org and defaults.project, no auth.token, and aren't ignored. The wizard says where the token went and to set SENTRY_AUTH_TOKEN in CI. There's no "DO NOT commit auth token" message.
iOS Release (bare) ✅ SENTRY_DOTENV_PATH=…/.env.sentry-build-plugin. Source maps uploaded, and 4 dSYMs. The JS error and the native crash both arrive symbolicated.
Android Release (bare) ✅ Source maps uploaded, and the JS error arrives symbolicated.
Control ✅ With .env.sentry-build-plugin removed, both builds fail at the upload: "Auth token is required for this request" on Android, "API request failed" on iOS. With the file back, both succeed. So the token comes from that file.
Second run ✅ Nothing duplicated, and no token warning: ".env.sentry-build-plugin already has auth token. Will not add one".
Set up first with @sentry/wizard 9.1.0 (token in sentry.properties) ✅ Warns for each sentry.properties with an auth.token line that it may already be committed, says to remove the line and rotate the token if it was pushed, and leaves both files unchanged (same checksum).
Expo with committed native folders (after expo prebuild) ✅ Same files as the bare app, and the iOS Release build uploads (SENTRY_DOTENV_PATH set, source maps plus 10 debug files).
Expo with generated native folders ✅ Unchanged: the token stays in the gitignored .env.local.

The nine patch-native-files.test.ts failures seen on macOS when merging this onto main are fixed by 93ab4eb. With this PR merged onto current main, typecheck passes and all 213 React Native wizard tests pass on macOS.

This also confirms that bare React Native Android reads .env.sentry-build-plugin: in @sentry/react-native 8.37.0, sentry.gradle delegates to sentry.gradle.kts, which reads it.

@antonis
antonis marked this pull request as ready for review December 3, 2026 10:28
@antonis
antonis added this pull request to the merge queue Dec 3, 2026

This branch was successfully deployed

1 active and 1 inactive deployments
Preview – cli — 93ab4eb2 Deployed Dec 3, 2026 by vercel[bot]
Preview – sentry-local — 93ab4eb2 Deployed Dec 3, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant