This project is archived and is in readonly mode.
Filter sensitive `QUERY_STRING` parameters in the log
-
Xavier Noria
Looks good, I'll try to apply it today.
-
Xavier Noria
Wonder if it is worth mentioning in actionpack/lib/action_dispatch/http/parameters_filter.rb that filtering is performed both in the logged parameters hash, and the query string. The current wording isn't clear about this (kind of implies only the hash, which is the current implementation).
-
Prem Sichanugrist (sikachu)
Yes, I think the documentation overthere should be updated as well. I'll update it and push to docrails :)
Thank you.
-
Xavier Noria
Good :).
It is better to update the patch, though. A complete patch has code, tests, and docs, as needed. If a test was missing we'd update the patch. If some docs revision is needed, it is better that it comes with the patch as well.
docrails is more for quick fixes and writing guides, it does not replace the need for self-contained commits to master :).
-
Prem Sichanugrist (sikachu)
Aha! I got your point. Let me get the patch cooking then ;)
-
Matt Jones
To play devil's advocate for a bit, isn't passing secrets in GET parameters generally a bad idea anyways? For instance, they still end up in the Apache logs if you're running with Passenger and would presumably end up in the logs of any proxy servers the request passes through.
-
Dan Pickett
I'm in agreement that it's bad practice, but I've definitely seen use cases where third parties require a GET with some silly things in the query string (Push type systems that send a unique identifier in a query string via a GET). While we can't guarantee it's not logged elsewhere, I still think it's good practice to have the option to have it omitted in the Rails logs.
I'm +1 on this once Prem's doc patch is attached.
-
Prem Sichanugrist (sikachu)
Here's the new patch with documentation.
-
Xavier Noria
I've played a bit with this feature.
I think it is worthwhile but see a few details that could still be improved:
-
If the user sends a genuine string "[FILTERED]" (encoded as %5BFILTERED%5D) as value or part of the value of an unfiltered parameter, the square brackets will be decoded in the logged query string, while they shouldn't.
-
At least in 1.8 the reconstructed query string in the log does not necessarily match the actual query string, because it does not necessarily preserve the order of the parameters (and in some of my tests it really doesn't).
-
If a parameter in the query string is repeated, say the "x" in "x=y&a=b&x=z", only one occurrence is shown in the reconstructed query string in the log. So it will also differ from the real query string.
Prem, do you think you could work on those ones?
-
-
Prem Sichanugrist (sikachu)
Nice catch! Yes, it seems like I've overlooked something in my patch. Will update it soon. :)
-
Prem Sichanugrist (sikachu)
- Assigned user changed from Prem Sichanugrist (sikachu) to Xavier Noria
I've update the patch to fixes those issues above, and add those cases as the test.
I've included patch for
masterand3-0-stable. The only difference is the CHANGELOG entry. -
Xavier Noria
Looks good to me. I have been working a bit on the patches:
-
Semicolon as a separator was untested
-
The edge case /foo?secret (no equal sign) was not handled properly, it was logged as /foo?secret=[FILTERED]
Will push them soon.
Thanks Prem!
-
-
Repository
- State changed from open to committed
(from [434e451221cd3d19e4575e26799ee53954347a03]) Filter sensitive query string parameters in the log [#6244 Filter sensitive `QUERY_STRING` parameters in the log state:committed]
This provides more safety to applications that put secret information in the query string, such as API keys or SSO tokens.
Signed-off-by: Xavier Noria fxn@hashref.com
https://github.com/rails/rails/commit/434e451221cd3d19e4575e26799ee... -
Repository
(from [68802d0fbe9d20ef8c5f6626d4b3279bd3a42d3e]) Filter sensitive query string parameters in the log [#6244 Filter sensitive `QUERY_STRING` parameters in the log state:committed]
This provides more safety to applications that put secret information in the query string, such as API keys or SSO tokens.
Signed-off-by: Xavier Noria fxn@hashref.com
https://github.com/rails/rails/commit/68802d0fbe9d20ef8c5f6626d4b32... -
Prem Sichanugrist (sikachu)
Thank you for updating my patch and push them for me. ;)
Jeez, seems like I keep overlooking something.
