@@ -486,38 +486,21 @@ paths-ignore:
486486
487487` ` ` ql
488488/**
489- * @name Find hardcoded secrets in C#
490- * @description Detects hardcoded string literals assigned to fields with secret-related names
489+ * @name Hardcoded secrets in C# code
490+ * @description Finds string literals that may contain hardcoded secrets.
491491 * @kind problem
492492 * @problem.severity warning
493493 * @security-severity 8.0
494494 * @id cs/hardcoded-secrets
495- * @tags security
495+ * @tags security, external/cwe/cwe-798
496496 */
497497
498498import csharp
499499
500- predicate isSecretField(Field f) {
501- f.getName().regexpMatch("(?i).*(apiKey|token|secret|password|auth)")
502- }
503-
504- predicate isSecretValue(string value) {
505- value.regexpMatch("(?i)^(sk_.*|token_.*|apikey_.*|[a-zA-Z0-9+/=]{32,})")
506- }
507-
508- from Field f, StringLiteral lit
509- where
510- isSecretField(f) and
511- f.getInitializer() = lit and
512- isSecretValue(lit.getValue())
513- select lit, "Hardcoded secret detected: '" + lit.getValue() + "' assigned to field '" + f.getName() + "'"
514- from Field f, StringLiteral lit
500+ from StringLiteral s
515501where
516- isSecretField(f) and
517- f.getInitializer() = lit and
518- isSecretValue(lit.getValue())
519- select lit, "Hardcoded secret detected: '" + lit.getValue() + "' assigned to field '" + f.getName() + "'"
520-
502+ s.getValue().matchesRegex("(?i)(sk_[a-z0-9]{10,}|api[_-]?key|token|secret|[A-Za-z0-9+/=]{32,})")
503+ select s, "🔒 Possible hardcoded secret: '" + s.getValue() + "'"
521504` ` `
522505
523506# ## 🔍 Purpose of `FindHardcodedSecrets.ql` Query
0 commit comments