Skip to content

Secrets filter: redact a secret in full when another secret is its prefix - #19

Open
RaphaelFakhri wants to merge 1 commit into
rails:mainfrom
RaphaelFakhri:fix/secrets-filter-overlapping
Open

RaphaelFakhri wants to merge 1 commit into
rails:mainfrom
RaphaelFakhri:fix/secrets-filter-overlapping

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

SecretsFilter joins the secret values into one Regexp.union in ENV order. Alternation takes the first alternative that matches, so when a shorter secret is a prefix of a longer one and comes first, the filter replaces only the shared prefix. The tail of the longer secret ends up in result.json and the run artifacts:

Lemans::SecretsFilter.new([ "tok-0123456789", "tok-0123456789-extended-secret" ])
  .filter("a=tok-0123456789-extended-secret")
# => "a=<filtered>-extended-secret"

Changes

  • Sort the secrets longest first before building the pattern, so the longest match wins at every position.
  • Add a test with one secret that prefixes another.
  • Add a changelog entry.

Testing

  • bundle exec ruby -Itest test/lemans/secrets_filter_test.rb: the new test fails without the change ("a=<filtered>-extended-secret b=<filtered>") and passes with it.
  • bundle exec rubocop: no offenses.

Fixes #18

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Secrets filter leaves the tail of a secret when another secret is its prefix

1 participant