Skip to content

Commit

Permalink
Fix Harden regular expression to used to strip secrets in logs (#4563)…
Browse files Browse the repository at this point in the history
… [ci fast]

Include option to strip secrets from single-quoted strings

Signed-off-by: Rob Syme <[email protected]>
  • Loading branch information
robsyme authored Dec 9, 2023
1 parent d3c2f33 commit 832bff2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class StringUtils {
return m.matches() ? m.group(1).toLowerCase() : null
}

static private Pattern multilinePattern = ~/"?(password|token|secret|license)"?\s?[:=]\s?"?(\w+)"?/
static private Pattern multilinePattern = ~/["']?(password|token|secret|license)["']?\s?[:=]\s?["']?(\w+)["']?/

static String stripSecrets(String message) {
if (message == null) {
Expand Down
16 changes: 9 additions & 7 deletions modules/nf-commons/src/test/nextflow/util/StringUtilsTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,15 @@ class StringUtilsTest extends Specification {
StringUtils.stripSecrets(SECRET) == EXPECTED

where:
SECRET | EXPECTED
'Hi\n here is the "password" : "1234"' | 'Hi\n here is the "password" : "********"'
'Hi\n here is the password : "1"' | 'Hi\n here is the password : "********"'
'Hi\n here is the password : "1"' | 'Hi\n here is the password : "********"'
'Hi\n "password" :"1" \n "token": "123"'| 'Hi\n "password" :"********" \n "token": "********"'
'Hi\n password :"1"\nsecret: "345"' | 'Hi\n password :"********"\nsecret: "********"'
'secret="abc" password:"1" more text' | 'secret="********" password:"********" more text'
SECRET | EXPECTED
'Hi\n here is the "password" : "1234"' | 'Hi\n here is the "password" : "********"'
'Hi\n here is the password : "1"' | 'Hi\n here is the password : "********"'
'Hi\n here is the password : \'1\'' | 'Hi\n here is the password : \'********\''
'Hi\n "password" :"1" \n "token": "123"' | 'Hi\n "password" :"********" \n "token": "********"'
'Hi\n "password" :\'1\' \n "token": "123"' | 'Hi\n "password" :\'********\' \n "token": "********"'
'Hi\n \'password\' :\'1\' \n \'token\': \'123\''| 'Hi\n \'password\' :\'********\' \n \'token\': \'********\''
'Hi\n password :"1"\nsecret: "345"' | 'Hi\n password :"********"\nsecret: "********"'
'secret="abc" password:"1" more text' | 'secret="********" password:"********" more text'
}

@Unroll
Expand Down

0 comments on commit 832bff2

Please sign in to comment.