File tree Expand file tree Collapse file tree 7 files changed +360
-32
lines changed Expand file tree Collapse file tree 7 files changed +360
-32
lines changed Original file line number Diff line number Diff line change 1+ name : " CodeQL Config"
2+ disable-default-queries : false
3+ queries :
4+ - uses : security-extended
5+ - uses : ./queries
6+ paths :
7+ - UserApp/
8+ paths-ignore :
9+ - ' **/test/**'
10+ - ' **/obj/**'
11+ - ' **/bin/**'
Original file line number Diff line number Diff line change 1+ name : " Org-Wide CodeQL Policy"
2+ disable-default-queries : false
3+ queries :
4+ -
uses :
org/[email protected] /csharp/security/FindHardcodedSecrets.ql 5+ - uses : security-and-quality
6+ languages :
7+ - csharp
8+ paths :
9+ - ' **/*.cs'
10+ rules :
11+ - id : cs/hardcoded-secrets
12+ severity : error
13+ paths :
14+ - ' UserApp/**/*.cs'
15+ mode : block
16+ message : |
17+ ❌ Hardcoded secrets detected. Please:
18+ 1. Remove embedded credentials
19+ 2. Use environment variables or secrets config
20+ 3. Follow secure development best practices
Original file line number Diff line number Diff line change 1+ name : userapp/secrets
2+ version : 0.0.1
3+ library : true
4+ dependencies :
5+ codeql/csharp-all : " *"
Original file line number Diff line number Diff line change 1+ /**
2+ * @name Find hardcoded secrets in C#
3+ * @description Detects hardcoded string literals assigned to fields with secret-related names
4+ * @kind problem
5+ * @problem.severity warning
6+ * @security-severity 8.0
7+ * @id cs/hardcoded-secrets
8+ * @tags security
9+ */
10+
11+ import csharp
12+
13+ predicate isSecretField ( Field f ) {
14+ f .getName ( ) .regexpMatch ( "(?i).*(apiKey|token|secret|password|auth)" )
15+ }
16+
17+ predicate isSecretValue ( string_literal s) {
18+ s .getValue ( ) .regexpMatch ( "(?i)^(sk_.*|token_.*|apikey_.*|[a-zA-Z0-9+/=]{32,})" )
19+ }
20+
21+ from Field f , string_literal s
22+ where
23+ isSecretField ( f ) and
24+ f .getInitializer ( ) = s and
25+ isSecretValue ( s )
26+ select s , "Hardcoded secret detected: '" + s .getValue ( ) + "' assigned to field '" + f .getName ( ) + "'"
Original file line number Diff line number Diff line change 1+ version : 2
2+ updates :
3+ - package-ecosystem : " nuget"
4+ directory : " /UserApp"
5+ schedule :
6+ interval : " daily"
7+ labels :
8+ - " dependencies"
9+ - " automerge"
10+ open-pull-requests-limit : 5
11+ commit-message :
12+ prefix : " 📦 deps:"
Original file line number Diff line number Diff line change 1+ name : CodeQL Scan
2+ on :
3+ push :
4+ branches : [main]
5+ paths :
6+ - ' **/*.cs'
7+ pull_request :
8+ branches : [main]
9+ paths :
10+ - ' **/*.cs'
11+ permissions :
12+ contents : read
13+ security-events : write
14+ jobs :
15+ analyze :
16+ name : CodeQL Analyze C#
17+ runs-on : ubuntu-latest
18+ steps :
19+ - uses : actions/checkout@v3
20+ - uses : actions/setup-dotnet@v3
21+ with :
22+ dotnet-version : ' 8.0.x'
23+ - uses : github/codeql-action/init@v3
24+ with :
25+ languages : csharp
26+ config-file : .github/codeql/config.yml
27+ - run : dotnet build UserApp/UserApp.csproj --configuration Release
28+ - uses : github/codeql-action/analyze@v3
You can’t perform that action at this time.
0 commit comments