-
Notifications
You must be signed in to change notification settings - Fork 187
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(core): censor novel secrets in querystring #526
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,22 +14,29 @@ const { | |
} = require('../src/http-middlewares/after/log-response'); | ||
|
||
// little helper to prepare a req/res pair like the http logger does | ||
const prepareTestRequest = (reqBody = {}, resBody = {}) => | ||
const prepareTestRequest = ({ | ||
reqBody = {}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Declaring params like this make them mostly function like python kwargs |
||
resBody = {}, | ||
reqQueryParams = '', | ||
} = {}) => | ||
prepareRequestLog( | ||
{ | ||
url: 'http://example.com', | ||
url: `http://example.com${ | ||
reqQueryParams ? '?' + querystring.stringify(reqQueryParams) : '' | ||
}`, | ||
method: 'POST', | ||
headers: { | ||
accept: 'application/json', | ||
}, | ||
// we usually stringify this in prepare-request.coerceBody, so mirror that behavior here | ||
body: JSON.stringify(reqBody), | ||
}, | ||
{ | ||
status: 200, | ||
headers: { | ||
'content-type': 'application/json', | ||
}, | ||
// we stringify this in prepare-request.coerceBody | ||
|
||
content: resBody, | ||
} | ||
); | ||
|
@@ -250,17 +257,18 @@ describe('logger', () => { | |
}; | ||
const logger = createlogger({ bundle }, options); | ||
|
||
const { message, data } = prepareTestRequest( | ||
{ | ||
const { message, data } = prepareTestRequest({ | ||
reqBody: { | ||
// value appears only here; logger needs to parse this out of a string to censor it properly | ||
access_token: 'super_secret', | ||
refresh_token: bundle.authData.refresh_token, | ||
}, | ||
{ | ||
resBody: { | ||
// same here | ||
access_token: 'some new token', | ||
} | ||
); | ||
}, | ||
reqQueryParams: { api_key: 'secret-key' }, | ||
}); | ||
|
||
logger(message, data); | ||
const response = await logger.end(); | ||
|
@@ -273,6 +281,7 @@ describe('logger', () => { | |
log_type: 'http', | ||
request_type: 'devplatform-outbound', | ||
request_url: 'http://example.com', | ||
request_params: 'api_key=:censored:10:ad15d65bcc:', | ||
request_method: 'POST', | ||
request_headers: 'accept: application/json', | ||
request_data: | ||
|
@@ -296,7 +305,9 @@ describe('logger', () => { | |
const logger = createlogger({ bundle }, options); | ||
|
||
const { message, data } = prepareTestRequest({ | ||
refresh_token: bundle.authData.refresh_token, | ||
reqBody: { | ||
refresh_token: bundle.authData.refresh_token, | ||
}, | ||
}); | ||
|
||
logger(message, data); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weirdly, the
logger.safe urls
test was failing for me locally, but not in CI in the last PR. Bumpingsecret-scrubber
locally didn't seem to change that. Not sure why CI didn't flag anything ¯\_(ツ)_/¯There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's odd. It passes for me locally. Just curious, what's your failing message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right? Weirdest thing.
Running
yarn main-tests -g "safe urls"
incore
directory gives:Same thing happens when running the full suite.
It sort of makes sense- the value is a url and doesn't have basic auth or a querystring. So I'm not sure why the test passed before. But, I think the current behavior is what we want. If something is explicitly a sensitive key, we should censor it. If it's not (but is in auth data), it's probably safe.