Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ inputs:
default: true
cache-dependency-path:
description: 'Used to specify the path to a dependency file (e.g., go.mod, go.sum)'
cache-write:
description: 'Whether to save the cache at the end of the workflow. Set to false for cache read-only mode, useful for preventing cache poisoning from untrusted PR builds.'
default: true
architecture:
description: 'Target architecture for Go to use. Examples: x86, x64. Will use system architecture by default.'
outputs:
Expand Down
5 changes: 5 additions & 0 deletions dist/cache-save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71548,6 +71548,11 @@ process.on('uncaughtException', e => {
function run(earlyExit) {
return __awaiter(this, void 0, void 0, function* () {
try {
const cacheWriteEnabled = core.getInput('cache-write');
if (cacheWriteEnabled === 'false') {
core.info('Cache write is disabled (read-only mode). Skipping cache save.');
return;
}
const cacheInput = core.getBooleanInput('cache');
if (cacheInput) {
yield cachePackages();
Expand Down
6 changes: 6 additions & 0 deletions src/cache-save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ process.on('uncaughtException', e => {

export async function run(earlyExit?: boolean) {
try {
const cacheWriteEnabled = core.getInput('cache-write');
if (cacheWriteEnabled === 'false') {
core.info('Cache write is disabled (read-only mode). Skipping cache save.');
return;
}
Comment on lines +21 to +27
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cache-write is being read via core.getInput() and compared to the string 'false', which is case-sensitive and inconsistent with the rest of the action’s boolean inputs (e.g., cache uses getBooleanInput). Consider using core.getBooleanInput('cache-write') and checking if (!cacheWriteEnabled) ... to correctly handle boolean-y values and avoid accidental cache saves when the input is set to something like False/FALSE/0/empty string.

Also, consider evaluating cache first and returning early when caching is disabled, before parsing/acting on cache-write, so a misconfigured cache-write value can’t affect workflows where cache: false (and to avoid logging “cache write disabled” when caching itself is off).

See below for a potential fix:

    const cacheInput = core.getBooleanInput('cache');
    if (!cacheInput) {
      return;
    }

    const cacheWriteEnabled = core.getBooleanInput('cache-write');
    if (!cacheWriteEnabled) {
      core.info('Cache write is disabled (read-only mode). Skipping cache save.');
      return;
    }

    await cachePackages();

    if (earlyExit) {
      process.exit(0);

Copilot uses AI. Check for mistakes.
Comment on lines +21 to +27
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds security-relevant behavior (skipping the post-step cache save when cache-write is false), but there doesn’t appear to be any unit test coverage for src/cache-save.ts today. Please add a Jest test that verifies cache.saveCache (or cachePackages) is not invoked and an info message is logged when cache-write is disabled, to prevent regressions.

Copilot uses AI. Check for mistakes.

const cacheInput = core.getBooleanInput('cache');
if (cacheInput) {
await cachePackages();
Expand Down
Loading