Skip to content

Commit

Permalink
Removed buggy database connection string redaction that may cause som…
Browse files Browse the repository at this point in the history
…e JSON string to be invalid. #594.
  • Loading branch information
vhadianto committed Oct 22, 2024
1 parent 95a6ad8 commit e664244
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
# pipes-fittings

Shared Pipes Component

## v1.6.2 [2024-10-22]

_Bug fixes_

* Removed buggy database connection string redaction that may cause some JSON string to be invalid. ([#594](https://github.com/turbot/pipe-fittings/issues/594)).

## v1.6.1 [2024-10-22]

_What's new_

* Support setting a variable of type Connection using a connection string or cloud workspace handle. ([#592](https://github.com/turbot/pipe-fittings/issues/592)).


Expand Down
6 changes: 4 additions & 2 deletions sanitize/sanitizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,15 @@ func (s *Sanitizer) SanitizeString(v string) string {
v = v[:r.start] + RedactedStr + v[r.end:]
}

v = redactDbConnectionPassword(v)
// found some cases that it causes a JSON string to be invalid, removing for now. The db connection string
// should be redacted by Basic Auth redaction anyway.
// v = redactDbConnectionPassword(v)
return v
}

// The database connection string is also redacted by the Basic Auth redaction, it will actually redact more than the
// plain db redaction
func redactDbConnectionPassword(connectionString string) string {
func RedactDbConnectionPassword(connectionString string) string {
// Define the regex to match and capture only the password part
re := regexp.MustCompile(`(?P<protocol>[^:]+://)(?P<username>[^:]+):(?P<password>[^@]+)(?P<rest>@.+)`)
// Replace only the password part with "REDACTED"
Expand Down
16 changes: 8 additions & 8 deletions sanitize/sanitizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ func TestSanitizer_SanitizeString(t *testing.T) {
},
// The database connection string is also redacted by the Basic Auth redaction, it will actually redact more than the
// plain db redaction
{
name: "database connection string",
opts: SanitizerOptions{
ImportCodeMatchers: false,
},
input: `{"connection":"mysql://user:1234abcd@localhost:3306/db"}`,
want: `{"connection":"mysql://user:` + RedactedStr + `@localhost:3306/db"}`,
},
// {
// name: "database connection string",
// opts: SanitizerOptions{
// ImportCodeMatchers: false,
// },
// input: `{"connection":"mysql://user:1234abcd@localhost:3306/db"}`,
// want: `{"connection":"mysql://user:` + RedactedStr + `@localhost:3306/db"}`,
// },
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit e664244

Please sign in to comment.