Skip to content

Commit 9148964

Browse files
fix(expo): Ensure authToken is not written to application package (#3630)
Co-authored-by: Karl Heinz Struggl <[email protected]>
1 parent 4200779 commit 9148964

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Fixes
6+
7+
- Don't add Expo Plugin option `authToken` to application bundle ([#3630](https://github.com/getsentry/sentry-react-native/pull/3630))
8+
- Expo plugin configurations are generelly stored in plain text, and are also automatically added to built app bundles, and are therefore considered insecure.
9+
- You should not set the auth token in the plugin config except for local testing. Instead, use the `SENTRY_AUTH_TOKEN` env variable, as pointed out in our [docs](https://docs.sentry.io/platforms/react-native/manual-setup/expo/).
10+
- In addition to showing a warning, we are now actively removing an `authToken` from the plugin config if it was set.
11+
- If you had set the auth token in the plugin config previously, **and** built and published an app with that config, you should [rotate your token](https://docs.sentry.io/product/accounts/auth-tokens/).
12+
313
## 5.19.0
414

515
This release contains upgrade of `sentry-android` dependency to major version 7. There are no breaking changes in the JS API. If you are using the Android API please check [the migration guide](https://docs.sentry.io/platforms/android/migration/#migrating-from-iosentrysentry-android-6x-to-iosentrysentry-android-700).

plugin/src/withSentry.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ interface PluginProps {
1414

1515
const withSentryPlugin: ConfigPlugin<PluginProps | void> = (config, props) => {
1616
const sentryProperties = getSentryProperties(props);
17+
18+
if (props && props.authToken) {
19+
// If not removed, the plugin config with the authToken will be written to the application package
20+
delete props.authToken;
21+
}
22+
1723
let cfg = config;
1824
if (sentryProperties !== null) {
1925
try {
@@ -33,12 +39,14 @@ const withSentryPlugin: ConfigPlugin<PluginProps | void> = (config, props) => {
3339
);
3440
}
3541
}
42+
3643
return cfg;
3744
};
3845

39-
const missingAuthTokenMessage = '# auth.token is configured through SENTRY_AUTH_TOKEN environment variable';
4046
const missingProjectMessage = '# no project found, falling back to SENTRY_PROJECT environment variable';
4147
const missingOrgMessage = '# no org found, falling back to SENTRY_ORG environment variable';
48+
const existingAuthTokenMessage = `# DO NOT COMMIT the auth token, use SENTRY_AUTH_TOKEN instead, see https://docs.sentry.io/platforms/react-native/manual-setup/`;
49+
const missingAuthTokenMessage = `# Using SENTRY_AUTH_TOKEN environment variable`;
4250

4351
export function getSentryProperties(props: PluginProps | void): string | null {
4452
const { organization, project, authToken, url = 'https://sentry.io/' } = props ?? {};
@@ -56,12 +64,7 @@ export function getSentryProperties(props: PluginProps | void): string | null {
5664
return `defaults.url=${url}
5765
${organization ? `defaults.org=${organization}` : missingOrgMessage}
5866
${project ? `defaults.project=${project}` : missingProjectMessage}
59-
${
60-
authToken
61-
? `# Configure this value through \`SENTRY_AUTH_TOKEN\` environment variable instead. See: https://docs.sentry.io/platforms/react-native/manual-setup/\nauth.token=${authToken}`
62-
: missingAuthTokenMessage
63-
}
64-
`;
67+
${authToken ? `${existingAuthTokenMessage}\nauth.token=${authToken}` : missingAuthTokenMessage}`;
6568
}
6669

6770
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access

0 commit comments

Comments
 (0)