Filter the app's filter_parameters from logged query strings and Referer/Location URLs - #65
Merged
Merged
Conversation
Rails filters the params it logs with config.filter_parameters, but the query string, Referer and Location that logtail-rack logs carry the same values in plain text. The spec app gets the filter_parameters Rails 8 generates for new apps. The tests pin that these apply to the logged query string, Referer and Location, that Procs are left out of the rack list, and that a rack list the app customised is kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Points logtail-rack at the claude/query-string-filters branch of logtail-ruby-rack in the root Gemfile and in every gemfiles/*.gemfile, so CI exercises HTTPEvents.query_string_filters. To be replaced by a follow-up commit that requires logtail-rack ~> 0.2, >= 0.2.9 once it's released. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The integration, which runs in the :logtail initializer after the app's config initializers, now sets HTTPEvents.query_string_filters to Rails.application.config.filter_parameters, without Procs, which rewrite values while query string filters match names. A list the app changed from rack's DEFAULT_QUERY_STRING_FILTERS is kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
logtail-rack 0.2.8 times responses with the monotonic clock, which Timecop doesn't freeze, so "Completed 200 OK in 0.0ms" no longer holds. The last CI run on main still resolved logtail-rack 0.2.7. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eleased" This reverts commit 1f15e11.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Rails filters the params it logs with
config.filter_parameters, but the request rows that logtail-rack writes carry the raw query string, andheaders_jsoncarries the rawRefererandLocationURLs. Yesterday's red-team foundpassword=hunter2andtoken=values in plain text inquery_string,RefererandLocationon all seven Rails versions it tested, while the params of the same request showed[FILTERED].logtail-rack 0.2.9 adds
HTTPEvents.query_string_filters(logtail/logtail-ruby-rack#29), with a default list of its own. This PR makes Rails apps use their ownfilter_parametersfor it, so URLs are filtered the same way as params.What changes:
:logtailinitializer after the app's config initializers,HTTPEvents.query_string_filtersis set toRails.application.config.filter_parameters. Procs are left out: in Rails they rewrite values, while query string filters only match names.query_string_filtersfrom rack'sDEFAULT_QUERY_STRING_FILTERS, for example in an initializer, its list is kept.Logtail::Integrations::Rails.filter_parameters_in_urls(filter_parameters)method, so it can be tested on its own.Behaviour and compatibility:
filter_parametersare logged as[FILTERED]inquery_stringand in the queries ofRefererandLocation. Before, they were logged raw.:email, so email addresses in query strings now become[FILTERED]too. Rack's own default doesn't includeemail.:password(the default before Rails 7) still logstoken=raw, like Rails logs its params. An app with an emptyfilter_parametersgets no URL filtering. To filter more, add names tofilter_parametersor setquery_string_filtersin an initializer.credit_card.codedon't matchcredit_card[code]in a query string. Plain names, partial names and Regexps work as they do for params.Targets the 0.3.0 minor; merge after 0.2.15 is released.
Depends on logtail-rack 0.2.9, which isn't released yet. The
TEMP: run CI against the logtail-rack branch until 0.2.9 is releasedcommit points the rootGemfileand everygemfiles/*.gemfileat theclaude/query-string-filtersbranch of logtail-ruby-rack, so CI runs against the real API. The gemspec floor isn't bumped here: at merge time, after logtail-rack 0.2.9 is released, the TEMP commit gets replaced by a follow-up commit that requireslogtail-rack ~> 0.2, >= 0.2.9. Until then this must not be merged.It also carries the "Expect real response durations in the request specs" commit that the other open logtail-rails PRs share, byte for byte: logtail-rack 0.2.8 times responses with the monotonic clock, which Timecop doesn't freeze, so the three specs expecting
0.0msnow fail against the released rack too.The first commit only adds the tests and is expected to fail on CI; the TEMP commit and the fix come after it.
🤖 Generated with Claude Code