Skip to content

Commit 19b322f

Browse files
committed
fix: address PR #36 review feedback
1 parent f3b380c commit 19b322f

3 files changed

Lines changed: 28 additions & 1 deletion

File tree

cmd/idpishield/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,10 @@ func runScan(args []string) error {
338338
return err
339339
}
340340

341+
if *asOutput && (*url != "" || *domains != "") {
342+
log.Printf("warning: --as-output ignores --url and --domains flags; use scan-output subcommand for output scanning")
343+
}
344+
341345
shieldConfig := idpi.Config{
342346
Mode: idpi.ParseMode(*mode),
343347
AllowedDomains: parseDomains(*domains),

internal/engine/scanner_output_code.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var outputFencedCodePattern = regexp.MustCompile("(?s)```([a-zA-Z0-9#+-]*)\\n(.*
2929
var outputShellLinePattern = regexp.MustCompile(`(?m)^\s*\$\s+\S+`)
3030

3131
var outputInlinePythonPattern = regexp.MustCompile(`\b(import\s+\w+|def\s+\w+\(|class\s+\w+|print\()`)
32-
var outputInlineJSHashPattern = regexp.MustCompile(`\b(function\s+\w*\(|const\s+\w+|let\s+\w+|require\()`)
32+
var outputInlineJSHashPattern = regexp.MustCompile(`\b(function\s+\w*\(|const\s+\w+\s*=|let\s+\w+\s*=|require\()`)
3333
var outputInlineGoPattern = regexp.MustCompile(`\b(package\s+\w+|func\s+\w+\(|import\s*\()`)
3434
var outputInlineBashPattern = regexp.MustCompile(`(?i)(#!/bin/bash|\bcurl\b|\bwget\b|\bchmod\b)`)
3535

internal/engine/scanner_output_pii.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ var outputPIIPublicIPPattern = regexp.MustCompile(`\b\d{1,3}(?:\.\d{1,3}){3}\b`)
4545
var outputPIINamePattern = regexp.MustCompile(`\b[A-Z][a-z]+ [A-Z][a-z]+\b`)
4646
var outputPIISecretAssignmentPattern = regexp.MustCompile(`(?i)\b(?:api[_\-]?key|token|secret|password)\b\s*[:=]\s*\S{8,}`)
4747
var outputPIISecretPrefixPattern = regexp.MustCompile(`\b(?:AKIA[0-9A-Z]{16}|ghp_[A-Za-z0-9]{36}|gho_[A-Za-z0-9]{36}|github_pat_[A-Za-z0-9_]{59}|sk-ant-[A-Za-z0-9\-_]{90,}|sk-[A-Za-z0-9]{20,}|hf_[A-Za-z0-9]{37}|npm_[A-Za-z0-9]{36}|AIza[0-9A-Za-z\-_]{35}|sk_live_[A-Za-z0-9]{24,}|pk_live_[A-Za-z0-9]{24,}|xox[baprs]-[0-9A-Za-z\-]{10,48})\b`)
48+
var outputPIIAzureSASPattern = regexp.MustCompile(`(?i)\bsig=[a-zA-Z0-9%]{40,}\b`)
49+
var outputPIIAWSSecretPattern = regexp.MustCompile(`\b[0-9a-zA-Z/+]{40}\b`)
4850

4951
var outputPIISSNContextWords = []string{"ssn", "social security", "social sec"}
5052
var outputPIIPhoneContextWords = []string{"phone", "call", "mobile", "cell", "tel", "contact"}
@@ -299,9 +301,30 @@ func redactPIIText(text string, details []piiMatch) string {
299301
func redactOutputSecrets(text string) string {
300302
out := outputPIISecretAssignmentPattern.ReplaceAllString(text, "[REDACTED-KEY]")
301303
out = outputPIISecretPrefixPattern.ReplaceAllString(out, "[REDACTED-KEY]")
304+
out = outputPIIAzureSASPattern.ReplaceAllString(out, "sig=[REDACTED-SAS]")
305+
out = redactAWSSecretKeys(out)
302306
return out
303307
}
304308

309+
// redactAWSSecretKeys redacts 40-char base64-like tokens that appear in AWS secret context.
310+
func redactAWSSecretKeys(text string) string {
311+
contextPattern := regexp.MustCompile(`(?i)\b(?:aws|secret)\b`)
312+
for _, loc := range outputPIIAWSSecretPattern.FindAllStringIndex(text, -1) {
313+
start := loc[0] - 50
314+
if start < 0 {
315+
start = 0
316+
}
317+
end := loc[1] + 50
318+
if end > len(text) {
319+
end = len(text)
320+
}
321+
if contextPattern.FindStringIndex(text[start:end]) != nil {
322+
text = text[:loc[0]] + "[REDACTED-AWS-SECRET]" + text[loc[1]:]
323+
}
324+
}
325+
return text
326+
}
327+
305328
// piiRedactionTag returns the canonical replacement tag for a detected PII type.
306329
func piiRedactionTag(t string) string {
307330
switch t {

0 commit comments

Comments
 (0)