Repository navigation
fix(cli): Keep the React Native wizard's auth token out of committed sentry.properties - #2829
Conversation
…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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
antonis
left a comment
There was a problem hiding this comment.
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.
|
@antonis Good catch, fixed in 1aa2925a. Like the Android wizard, it checks what |
antonis
left a comment
There was a problem hiding this comment.
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.
|
@antonis Fixed in 93ab4eb2. The test file now mocks |
|
Tested end to end. Build:
To keep the token from coming from anywhere else, builds ran with
The nine This also confirms that bare React Native Android reads |
Reported as a security issue in getsentry/sentry-react-native#7166.
sentry wizard reactNativewrote the auth token toios/sentry.propertiesandandroid/sentry.propertieswithout 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/wizardbehaves the same. The same steps run for Expo projects whose native folders are committed. The.sentryclircpart of the report was already fixed by #2571.Which SDK versions read
.env.sentry-build-plugingetsentry/sentry-react-native#4281 shipped in 6.3.0 and made all three upload paths point sentry-cli at
$reactRoot/.env.sentry-build-pluginthroughSENTRY_DOTENV_PATH:scripts/sentry-xcode.sh,scripts/sentry-xcode-debug-files.sh, and the Groovysentry.gradle. 6.2.0 has none of them. getsentry/sentry-react-native#6119 (8.14.0) only portedsentry.gradletosentry.gradle.ktsand 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. Theauth.token/SENTRY_AUTH_TOKENcheck insentry.gradleonly runs withflavorAware, which the wizard doesn't set.What the wizard does now
SENTRY_AUTH_TOKENwith the existingaddDotEnvSentryBuildPluginFile, which also gitignores.env.sentry-build-plugin. Bothsentry.propertiesfiles get onlydefaults.org,defaults.projectand, on self-hosted,defaults.url, and stay committed.CliSetupConfigContent.authTokenis now optional, andaddSentryCliConfigalready 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 setSENTRY_AUTH_TOKENin CI, with the org's auth token settings URL. CI doesn't needSENTRY_URL, sincedefaults.urlstays in the committed files (on SaaS, sentry-cli's default URL is used).sentry.properties), and warns that the files hold the token and are committed. It suggests upgrading the SDK or switching toSENTRY_AUTH_TOKEN.auth.token: when asentry.propertiesalready has anauth.tokenline, 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.addExpoEnvLocal(.env.local) is unchanged..env.sentry-build-pluginends 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.auth-token-location, is set to.env.sentry-build-pluginorsentry.properties.auth-token-placeholderrecords whether the dotenv file holds the placeholder.The
sentry wizarddocs 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]