Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit 43158aa

Browse files
Merge pull request #564 from stacklok/contigous-secrets
fix: Notify to secrets to DB on complete redacted text
2 parents 81fc260 + 55957b1 commit 43158aa

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/codegate/pipeline/secrets/secrets.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,13 @@ def obfuscate(self, text: str) -> tuple[str, int]:
135135
# Store matches for logging
136136
found_secrets = 0
137137

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

143143
# Replace the secret in the text
144144
protected_text[start:end] = hidden_secret
145-
146-
self._notify_secret(match, protected_text)
147145
found_secrets += 1
148146
# Log the findings
149147
logger.info(
@@ -153,6 +151,10 @@ def obfuscate(self, text: str) -> tuple[str, int]:
153151
f"\nEncrypted: {hidden_secret}"
154152
)
155153

154+
# Second pass. Notify the secrets in DB over the complete protected text.
155+
for _, _, match in absolute_matches:
156+
self._notify_secret(match, protected_text)
157+
156158
# Convert back to string
157159
protected_string = "".join(protected_text)
158160
print(f"\nProtected text:\n{protected_string}")

0 commit comments

Comments
 (0)