@@ -9,103 +9,87 @@ permissions:
99 security-events : write
1010
1111jobs :
12- security-scan :
13- name : Universal Security Scanner
12+ # ##############################################
13+ # 1. Detect repository languages dynamically
14+ # ##############################################
15+ detect-languages :
1416 runs-on : ubuntu-latest
17+ outputs :
18+ languages : ${{ steps.detect.outputs.languages }}
1519
1620 steps :
17- - name : Checkout repository
18- uses : actions/checkout@v4
21+ - name : Detect languages from GitHub API
22+ id : detect
23+ uses : actions/github-script@v7
24+ with :
25+ script : |
26+ const repo = context.repo;
27+ const res = await github.rest.repos.listLanguages({
28+ owner: repo.owner,
29+ repo: repo.repo
30+ });
31+
32+ const langMap = res.data;
33+ const supported = {
34+ "JavaScript": "javascript",
35+ "TypeScript": "javascript",
36+ "Python": "python",
37+ "Go": "go",
38+ "Ruby": "ruby",
39+ "Java": "java",
40+ "PHP": "cpp", // CodeQL uses C/C++ for PHP security (closest match)
41+ "C": "cpp",
42+ "C++": "cpp"
43+ };
44+
45+ const detected = Object.keys(langMap)
46+ .filter(lang => supported[lang])
47+ .map(lang => supported[lang]);
48+
49+ if (detected.length === 0) {
50+ detected.push("javascript"); // default fallback
51+ }
52+
53+ return {
54+ languages: JSON.stringify([...new Set(detected)])
55+ };
56+
57+ # ##############################################
58+ # 2. Run GITLEAKS (strong secret scanner)
59+ # ##############################################
60+ gitleaks :
61+ runs-on : ubuntu-latest
62+ steps :
63+ - uses : actions/checkout@v4
1964 with :
2065 fetch-depth : 0
2166
22- # -----------------------------
23- # 1. GITLEAKS
24- # -----------------------------
2567 - name : Run Gitleaks
2668 uses : gitleaks/gitleaks-action@v2
2769 with :
28- args : detect --source . --no-git
70+ args : detect --source . --verbose --redact
2971
30- # -----------------------------
31- # 2. TRUFFLEHOG
32- # -----------------------------
33- - name : Run TruffleHog
34- uses : trufflesecurity/trufflehog@main
35- with :
36- scan : filesystem
37- path : " ."
38-
39- # -----------------------------
40- # 3. detect-secrets
41- # -----------------------------
42- - name : Install detect-secrets
43- run : pip install detect-secrets
44-
45- - name : Run detect-secrets
46- run : |
47- detect-secrets scan > .secrets.baseline
48- detect-secrets audit .secrets.baseline || exit 1
49-
50- # -----------------------------
51- # 4. Dependency Scanners (auto)
52- # -----------------------------
53-
54- # NodeJS
55- - name : npm audit (only if package.json exists)
56- if : hashFiles('package.json') != ''
57- run : |
58- npm install --ignore-scripts
59- npm audit --audit-level=high
60-
61- # Python
62- - name : pip-audit (only if requirements.txt exists)
63- if : hashFiles('requirements.txt') != ''
64- uses : pypa/gh-action-pip-audit@v1.0.8
65-
66- # PHP Composer
67- - name : Composer audit (only if composer.json exists)
68- if : hashFiles('composer.json') != ''
69- run : |
70- sudo apt-get update
71- sudo apt-get install -y composer
72- composer install --no-scripts
73- composer audit || true
74-
75- # Go
76- - name : Go vet (only if go.mod exists)
77- if : hashFiles('go.mod') != ''
78- uses : actions/setup-go@v5
79- with :
80- go-version : ' stable'
81- - name : Go vulnerability check
82- if : hashFiles('go.mod') != ''
83- run : |
84- go mod tidy
85- go vet ./...
86- go list -json -deps ./... | go vuln check
87-
88- # -----------------------------
89- # 5. CODEQL (Auto-detect languages)
90- # -----------------------------
72+ # ##############################################
73+ # 3. Run CodeQL using auto-detected languages
74+ # ##############################################
9175 codeql :
92- permissions :
93- contents : read
94- security-events : write
95-
76+ needs : [detect-languages]
9677 runs-on : ubuntu-latest
9778
79+ strategy :
80+ matrix :
81+ language : ${{ fromJson(needs.detect-languages.outputs.languages) }}
82+
9883 steps :
99- - name : Checkout code
100- uses : actions/checkout@v4
84+ - uses : actions/checkout@v4
10185
10286 - name : Initialize CodeQL
10387 uses : github/codeql-action/init@v3
10488 with :
105- languages : auto
89+ languages : ${{ matrix.language }}
10690
10791 - name : Autobuild
10892 uses : github/codeql-action/autobuild@v3
10993
110- - name : Analyze
94+ - name : Perform CodeQL Analysis
11195 uses : github/codeql-action/analyze@v3
0 commit comments