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

[docs] Change regular expression used in Logger middleware example #1281

Closed
mvastola opened this issue May 16, 2021 · 4 comments · Fixed by #1378
Closed

[docs] Change regular expression used in Logger middleware example #1281

mvastola opened this issue May 16, 2021 · 4 comments · Fixed by #1378

Comments

@mvastola
Copy link

The online documentation for the :logger middleware contains this block:

  faraday.response :logger do | logger |
    logger.filter(/(api_key=)(\w+)/, '\1[REMOVED]')
  end

While most API keys are indeed alphanumeric, some keys/secrets contain periods, dashes, or are entirely base64-encoded.

As a result, I wanted to suggest replacing the \w+ in this regex with [^&]+. (Barring any unforeseen reason on my part why that shouldn't be the case.)

My thinking is that knowing the intricacies of regexes isn't otherwise needed to use this gem, and someone using the gem could very easily copy this from the docs, replacing api_key with any other parameter name (say, password), and think they are fully/securely omitting sensitive data from their logs.

Ideally, perhaps the logger middleware could take a list of param/header names to redact values for, in addition to regexes, (or perhaps even use Rails' by default, if defined?(Rails) && Rails.application.config&.filter_parameters), but that might be considered beyond the scope of this documentation tweak.

@olleolleolle
Copy link
Member

I think this sounds like a careful and helpful change - perhaps even a contextual detail about the regex ("match until the next &") .

You gave good context for when and why this would help a user.

I'm for it! Do you want to offer a PR?

@iMacTia
Copy link
Member

iMacTia commented May 17, 2021

I very much welcome a PR for either improving the doc or adding functionality ("perhaps the logger middleware could take a list of param/header names to redact values for"), but in case of the latter we definitely don't want features to only work under Rails, so that would need a framework-agnostic implementation

@mvastola
Copy link
Author

Ok. I've been pretty swamped but I'll try for next week. If someone wants to do it before I get to it, it's all yours.

@olleolleolle olleolleolle changed the title Potential Documentation Fix [docs] Change regular expression used in Logger middleware example May 20, 2021
@olleolleolle
Copy link
Member

For anyone who would like to fix this:

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

Successfully merging a pull request may close this issue.

3 participants