diff --git a/.github/workflows/publish-package.yml b/.github/workflows/publish-package.yml index 9f49416..1cf10f3 100644 --- a/.github/workflows/publish-package.yml +++ b/.github/workflows/publish-package.yml @@ -43,7 +43,6 @@ jobs: run: pnpm run build - name: Publish to GitHub Packages - continue-on-error: true run: | echo "@ritualdev-lab:registry=https://npm.pkg.github.com" > .npmrc echo "//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}" >> .npmrc diff --git a/action.yml b/action.yml index a3cc39e..1dac630 100644 --- a/action.yml +++ b/action.yml @@ -27,6 +27,10 @@ inputs: description: "Path to export OASIS SARIF 2.1.0 report (for GitHub Code Scanning upload-sarif)" required: false default: ".agentshield.sarif" + strict: + description: "Enforce immutable security root policy (--strict) preventing untrusted PR ignore rules from neutering secret scans (default: true)" + required: false + default: "true" runs: using: "composite" @@ -40,9 +44,13 @@ runs: INPUT_POST_PR_COMMENT: ${{ inputs.post_pr_comment }} INPUT_ANNOTATE_DIFF: ${{ inputs.annotate_diff }} INPUT_SARIF_FILE: ${{ inputs.sarif_file }} + INPUT_STRICT: ${{ inputs.strict }} ACTION_PATH: ${{ github.action_path }} run: | EXTRA_FLAGS="" + if [ "$INPUT_STRICT" = "true" ]; then + EXTRA_FLAGS="$EXTRA_FLAGS --strict" + fi if [ "$INPUT_ANNOTATE_DIFF" = "true" ]; then EXTRA_FLAGS="$EXTRA_FLAGS --annotate" fi diff --git a/src/ci.ts b/src/ci.ts index 6f94dc7..153b931 100644 --- a/src/ci.ts +++ b/src/ci.ts @@ -126,10 +126,43 @@ export class CiGateRunner { let configTampered = false; const configTouched = rawDiffList.some((f) => - /(?:^\.?agentshield(?:\.config)?\.json$)/i.test(f), + /(?:^\.?agentshield(?:\.config)?\.json$|^\.agentshieldignore$)/i.test(f), ); if (configTouched) { + // Fail-closed check: reject blanket wildcard ignores in .agentshieldignore (SEC-02) + const ignoreTouched = rawDiffList.some((f) => /^\.agentshieldignore$/i.test(f)); + if (ignoreTouched) { + try { + const ignoreContent = readFileSync(`${this.rootDir}/.agentshieldignore`, "utf8"); + const maliciousGlob = ignoreContent + .split("\n") + .map((l) => l.trim()) + .some( + (l) => + l && + !l.startsWith("#") && + (l === "*" || l === "**/*" || l === "**/.*" || /^!\s*secrets\b/i.test(l)), + ); + if (maliciousGlob) { + return { + passed: false, + totalSecrets: 0, + criticalCount: 1, + highCount: 0, + filesScanned: rawDiffList.length, + findings: [], + markdownReport: + "## 🛡️ AgentShield CI/CD Security Gate Report\n\n### 🚨 Fatal Policy Violation (--strict): Malicious Blanket Ignore Detected in `.agentshieldignore`\nPR attempted to add blanket wildcard/inverted ignore rules (`*`, `**/*`, `**/.*`). Merging blocked.", + scanError: "Malicious wildcard glob detected in .agentshieldignore (--strict)", + baseRef: sanitizedBase, + configTampered: true, + }; + } + } catch { + // Ignore if deleted + } + } try { const baseConfigRaw = execFileSync("git", ["show", `${sanitizedBase}:.agentshield.json`], { encoding: "utf8",