From 5a11830cdcd183f74209a1755d58216a8af6f60c Mon Sep 17 00:00:00 2001 From: Salman Chishti <13schishti@gmail.com> Date: Mon, 9 Mar 2026 05:35:59 -0700 Subject: [PATCH] feat: add cache-write input for read-only cache mode Add a 'cache-write' input (default: true) that controls whether the cache is saved at the end of the workflow. When set to 'false', the action will restore cached dependencies but skip saving, providing a read-only cache mode. This is useful for preventing cache poisoning attacks from untrusted PR builds while still benefiting from cached dependencies. --- action.yml | 4 ++++ dist/cache-save/index.js | 5 +++++ src/cache-save.ts | 6 ++++++ 3 files changed, 15 insertions(+) diff --git a/action.yml b/action.yml index 861fb9d75..bd91a24a4 100644 --- a/action.yml +++ b/action.yml @@ -24,6 +24,10 @@ inputs: cache-dependency-path: description: 'Used to specify the path to a dependency file: packages.lock.json. Supports wildcards or a list of file names for caching multiple dependencies.' required: false + 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.' + required: false + default: true workloads: description: 'Optional SDK workloads to install for additional platform support. Examples: wasm-tools, maui, aspire.' required: false diff --git a/dist/cache-save/index.js b/dist/cache-save/index.js index 43e7b8b61..6636f730d 100644 --- a/dist/cache-save/index.js +++ b/dist/cache-save/index.js @@ -44650,6 +44650,11 @@ process.on('uncaughtException', e => { }); async function run() { try { + const cacheWriteEnabled = core.getInput('cache-write'); + if (cacheWriteEnabled === 'false') { + core.info('Cache write is disabled (read-only mode). Skipping cache save.'); + return; + } if (core.getBooleanInput('cache')) { await cachePackages(); } diff --git a/src/cache-save.ts b/src/cache-save.ts index 3f942b9a6..dbfa4dd8b 100644 --- a/src/cache-save.ts +++ b/src/cache-save.ts @@ -14,6 +14,12 @@ process.on('uncaughtException', e => { export async function run() { try { + const cacheWriteEnabled = core.getInput('cache-write'); + if (cacheWriteEnabled === 'false') { + core.info('Cache write is disabled (read-only mode). Skipping cache save.'); + return; + } + if (core.getBooleanInput('cache')) { await cachePackages(); }