GH-200 practice question 6 of 15

As a developer, what is the safest way to reference an action to prevent modification of the underlying code?

Full set: 100 questions
Answer options
A: Use a commit hash. Correct answer
B: Use a branch name.
C: Use a patch release tag.
D: Use a major release tag.
Correct Answer:
A. Use a commit hash.
Explanation

Using a full-length commit SHA (Secure Hash Algorithm) is the safest and most immutable way to reference a GitHub Action. A commit SHA uniquely identifies a specific version of the code at a single point in time. Unlike branches or tags, which are pointers that can be moved to different commits, a SHA is permanent. This guarantees that your workflow will always execute the exact same code, protecting it from potentially malicious or breaking changes that could be introduced if referencing a mutable tag or branch.

Why Incorrect

B. Use a branch name: A branch is a mutable pointer; code on the branch can change at any time, introducing instability or security risks.
C. Use a patch release tag: Tags are mutable. They can be deleted and re-created to point to a different commit, making them less secure than a SHA.
D. Use a major release tag: Like other tags, major release tags can be moved, posing the same security and stability risks.

References

GitHub Docs

"Security hardening for GitHub Actions". The section "Using third-party actions" explicitly states: "Pinning an action to a full length commit SHA is the most secure option... This will ensure you are using an immutable version of the action."

GitHub Docs

"Using actions in a workflow". This document shows the syntax for referencing actions using a branch

tag

or a specific commit SHA

noting the trade-offs.

Scroll to Top