question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Remove API key from headers in error message

See original GitHub issue

This was originally posted as a bug https://github.com/axios/axios/issues/4246 but the GitHub bot didn’t seem to like it. Trying again here as a feature request.

Describe the issue

I am catching the error responses from Axios when a request fails. I then use the error request to create logs, log to console or return to the browser. In many of these instances the error contains axios.defaults.headers.common.Authorization set before the request. I started going through deleting them before logging, but they are all over in the response and request, and {config} with the response and request. So far I have:

obj.config.headers.Authorization
obj.request._header
obj.response.request._header
obj.request._currentRequest._header

Likely more, but have stopped looking.

Ideally there would be a way to clean this up automatically so the outputs are safe to use anywhere.

To Reproduce

Any failed request

New feature.

Remove the Authorisation headers so error message can be used safely, with option to include them for debug.

Environment

  • Axios Version [0.24.0]

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
github-actions[bot]commented, Nov 5, 2021

Hello! 👋

This issue is being automatically closed because it does not follow the issue template. Please read the issue template carefully and follow all of the instructions when opening a new issue.

Thanks

0reactions
jasonsaaymancommented, Sep 6, 2022

I still disagree, firstly you should not be logging the entire response in any use case ever, what should be done is you should log only the parts of the response that you would like to keep for traces and to identify errors. When logging the entire response you are actually creating multiple potential issues, you could be logging user data, you can be breaching GDPR and you can even be login their credentials as that request data is in there too.

Also realistically the above suggestion would not cover all use cases by a long stretch. People implement any key-value pair they want for the token sometimes, amazon re-writes the key values when under an API gateway and the list goes on so it would theoretically be impossible for us to strip all of the possible tokens and credentials from the response object.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Headers.delete() - Web APIs - MDN Web Docs
The delete() method of the Headers interface deletes a header from the current Headers object.
Read more >
Solved: CORS error - Request header field x-apikey is not
Solved: Clients send a request with their API key in the header. The filed name is "x-apikey". And I am trying to enable...
Read more >
Use a mapping template to override an API's request and ...
Any type of request parameter, response header, or response status code may be ... of a json body and remap key value pairs...
Read more >
AWS Api Gateway Lambda Integration is not working with api ...
What I did was to remove api key requirement and changing "Access-Control-Allow-Origin":"*" to "Access-Control-Allow-Origin":"https://example.
Read more >
Error Messages | Maps JavaScript API - Google Developers
Please check the API restrictions settings of your API key in the Google Cloud Console to ensure that all of the APIs and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found