Skip to content

Commit d8e544e

Browse files
authored
Fix cache key hashing (#153)
This fixes cache key computation to be similar to [what GHA's actions toolkit](https://github.com/actions/toolkit/blob/0786132e6a1a4451c2d392bbbf481c2b172d4312/packages/glob/src/internal-hash-files.ts#L31-L34) does, to avoid a certain class of (unlikely but possible) cache key collision and cache poisoning.
1 parent cd7e67c commit d8e544e

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

‎dist/index.cjs‎

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/cache.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,12 @@ async function hashConfigFiles(workingDirectory: string): Promise<string> {
103103
for (const file of files.sort()) {
104104
digest.update(path.relative(workingDirectory, file))
105105
digest.update('\0')
106-
digest.update(await fs.readFile(file))
107-
digest.update('\0')
106+
digest.update(
107+
crypto
108+
.createHash('sha256')
109+
.update(await fs.readFile(file))
110+
.digest(),
111+
)
108112
}
109113
return digest.digest('hex')
110114
}

0 commit comments

Comments
 (0)