Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Improve token redaction in CLI arg logging #2118

Merged
merged 1 commit into from
Aug 2, 2024

Conversation

szokeasaurusrex
Copy link
Member

#2115 aimed to redact auth tokens when logging the arguments to the CLI. Although that change addressed some cases where auth tokens were passed as a CLI argument, not all cases were addressed. For example, the following was redacted properly with #2115:

sentry-cli --auth-token this-gets-redacted --log-level=info info

But, the following was not:

sentry-cli --auth-token=this-does-not-get-redacted --log-level=info info

The difference is that in the second example, the auth token is passed with --auth-token=token rather than separated by whitespace --auth-token token.

This change improves the redacting so that auth tokens passed like --auth-token=token are also redacted. The change also redacts any non-whitespace-containing substrings starting with sntrys_ or sntryu_ (prefixes that all auth tokens generated in the latest version of Sentry should start with), so that if an auth token appears where it is not expected, we redact it. For example, the following would be redacted with this change:

sentry-cli --auth=sntrys_my-token-passed-as-non-existing-auth-argument --log-level=info info

Note that as in #2115, this change is only relevant in the case where the log level is set to info or debug (the default is warn) – command line arguments are logged at the info level.

#2115 aimed to redact auth tokens when logging the arguments to the CLI. Although that change addressed some cases where auth tokens were passed as a CLI argument, not all cases were addressed. For example, the following was redacted properly with #2115:

```sh
sentry-cli --auth-token this-gets-redacted --log-level=info info
```

But, the following was not:

```sh
sentry-cli --auth-token=this-does-not-get-redacted --log-level=info info
```

The difference is that in the second example, the auth token is passed with `--auth-token=token` rather than separated by whitespace `--auth-token token`.

This change improves the redacting so that auth tokens passed like `--auth-token=token` are also redacted. The change also redacts any non-whitespace-containing substrings starting with `sntrys_` or `sntryu_` (prefixes that all auth tokens generated in the latest version of Sentry should start with), so that if an auth token appears where it is not expected, we redact it. For example, the following would be redacted with this change:

```sh
sentry-cli --auth=sntrys_my-token-passed-as-non-existing-auth-argument --log-level=info info
```

Note that as in #2115, this change is only relevant in the case where the log level is set to `info` or `debug` (the default is `warn`) – command line arguments are logged at the `info` level.
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/auth-token-redacting branch from 6669030 to 5c1ac1f Compare August 2, 2024 09:53
Copy link
Contributor

@loewenheim loewenheim left a comment

Choose a reason for hiding this comment

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

Very thorough!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants