Skip to content

Commit

Permalink
Merge pull request #564 from stacklok/contigous-secrets
Browse files Browse the repository at this point in the history
fix: Notify to secrets to DB on complete redacted text
  • Loading branch information
aponcedeleonch authored Jan 13, 2025
2 parents 81fc260 + 55957b1 commit 43158aa
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/codegate/pipeline/secrets/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,13 @@ def obfuscate(self, text: str) -> tuple[str, int]:
# Store matches for logging
found_secrets = 0

# Replace each match with its encrypted value
# First pass. Replace each match with its encrypted value
logger.info("\nFound secrets:")
for start, end, match in absolute_matches:
hidden_secret = self._hide_secret(match)

# Replace the secret in the text
protected_text[start:end] = hidden_secret

self._notify_secret(match, protected_text)
found_secrets += 1
# Log the findings
logger.info(
Expand All @@ -153,6 +151,10 @@ def obfuscate(self, text: str) -> tuple[str, int]:
f"\nEncrypted: {hidden_secret}"
)

# Second pass. Notify the secrets in DB over the complete protected text.
for _, _, match in absolute_matches:
self._notify_secret(match, protected_text)

# Convert back to string
protected_string = "".join(protected_text)
print(f"\nProtected text:\n{protected_string}")
Expand Down

0 comments on commit 43158aa

Please sign in to comment.