This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: github-actions-composite-action-cache

GitHub Actions Composite Actions & Immutable SHA Action Pinning Standard

CI/CD security and modularity standard for GitHub Actions. Mandates pinning third-party actions to immutable full 40-character commit SHAs with comment tags (e.g. actions/checkout@v4 -> actions/checkout@11bd71... # v4.2.2), preventing supply-chain tag mutation attacks, and utilizing composite actions for DRY pipeline reuse.

Prohibited Anti-Pattern: AI references unpinned major tags (@v1, @main) for third-party GitHub Actions, leaving pipelines vulnerable to supply chain tag hijacking.

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: GitHub Actions Composite Actions & Immutable SHA Action Pinning Standard - CI/CD security and modularity standard for GitHub Actions. Mandates pinning third-party actions to immutable full 40-character commit SHAs with comment tags (e.g. actions/checkout@v4 -> actions/checkout@11bd71... # v4.2.2), preventing supply-chain tag mutation attacks, and utilizing composite actions for DRY pipeline reuse.
globs: **/.github/workflows/*.yml, **/.github/workflows/*.yaml, **/action.yml
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/github-actions-composite-action-cache"
---

# GitHub Actions Composite Actions & Immutable SHA Action Pinning Standard

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: AI references unpinned major tags (@v1, @main) for third-party GitHub Actions, leaving pipelines vulnerable to supply chain tag hijacking.

## System Constraints
You are a DevSecOps CI/CD Security Specialist. In GitHub Actions workflows, NEVER reference third-party actions using mutable git tags (@v3, @main). A compromised maintainer account or force-pushed git tag can instantly execute malicious scripts with access to GITHUB_TOKEN and repo secrets. Always pin to immutable 40-character commit SHAs.

## Strict Guidelines
- MUST pin all external actions to immutable 40-character commit hashes: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2.
- MUST restrict default GITHUB_TOKEN permissions at workflow top-level: permissions: contents: read.
- MUST NOT interpolate un-sanitized context variables (${{ github.event.issue.title }}) directly into run: bash scripts (prevents script injection).
- SHOULD abstract duplicated multi-step setups into local composite actions (.github/actions/setup-node-pnpm).
- SHOULD configure actions/cache with restore-keys for deterministic caching.

## Bad vs Good Implementations
### Immutable SHA Pinning and Minimal Permissions in GitHub Actions

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Mutable branch or tag references can be overwritten upstream to deliver malicious payloads. Inlining untrusted GitHub issue titles directly into bash scripts allows script injection.
```yaml
# FATAL: Mutable tags and unrestricted permissions
name: CI
on: [push]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      # VULNERABLE: Tag @v3 can be retagged by an attacker to run malicious cryptominer/secret stealer!
      - uses: actions/checkout@v3
      - run: echo "Issue: ${{ github.event.issue.title }}" # SCRIPT INJECTION VULNERABILITY!
```

#### Production Standard (Correct)
> **Standard**: Pins actions to immutable commit SHAs with version comments, restricts default permissions, and passes user input safely via environment variables to eliminate script injection.
```yaml
name: CI
on: [push]

# Minimal least-privilege token permissions
permissions:
  contents: read

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      # Immutable full commit SHA pinning protects against supply chain compromise
      - name: Checkout Repository
        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

      - name: Safe Parameter Handling via Environment Variables
        env:
          ISSUE_TITLE: ${{ github.event.issue.title }}
        run: |
          # Safe: Variable passed via env, not inlined into bash script
          echo "Issue title: $ISSUE_TITLE"
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: GitHub Actions Composite Actions & Immutable SHA Action Pinning Standard

GitHub Actions Composite Actions & Immutable SHA Action Pinning Standard defines an industrial-grade behavioral standard for devops engineering. CI/CD security and modularity standard for GitHub Actions. Mandates pinning third-party actions to immutable full 40-character commit SHAs with comment tags (e.g. actions/checkout@v4 -> actions/checkout@11bd71... # v4.2.2), preventing supply-chain tag mutation attacks, and utilizing composite actions for DRY pipeline reuse. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: AI references unpinned major tags (@v1, @main) for third-party GitHub Actions, leaving pipelines vulnerable to supply chain tag hijacking. Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftAI references unpinned major tags (@v1, @main) for third-party GitHub Actions, leaving pipelines vulnerable to supply chain tag hijacking.Critical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

MUST pin all external actions to immutable 40-character commit hashes

MUST pin all external actions to immutable 40-character commit hashes: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

MUST restrict default GITHUB_TOKEN permissions at workflow top-level

MUST restrict default GITHUB_TOKEN permissions at workflow top-level: permissions: contents: read.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

MUST NOT interpolate un-sanitized context variables (${{ github.event.issue.title }}) directly into run

MUST NOT interpolate un-sanitized context variables (${{ github.event.issue.title }}) directly into run: bash scripts (prevents script injection).

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

SHOULD abstract duplicated multi-step setups into local composite actions (.github/actions/setup-node-pnpm).

SHOULD abstract duplicated multi-step setups into local composite actions (.github/actions/setup-node-pnpm).

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

SHOULD configure actions/cache with restore-keys for deterministic caching.

SHOULD configure actions/cache with restore-keys for deterministic caching.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is GitHub Actions Composite Actions & Immutable SHA Action Pinning Standard critical for AI coding assistants?

CI/CD security and modularity standard for GitHub Actions. Mandates pinning third-party actions to immutable full 40-character commit SHAs with comment tags (e.g. actions/checkout@v4 -> actions/checkout@11bd71... # v4.2.2), preventing supply-chain tag mutation attacks, and utilizing composite actions for DRY pipeline reuse. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (AI references unpinned major tags (@v1, @main) for third-party GitHub Actions, leaving pipelines vulnerable to supply chain tag hijacking.) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

1 Rule in Stack

GitHub