Skip to content

Commit 662d3dd

Browse files
committed
refactor(python): add SHA-256 checksum verification for python-build-standalone
Add checksum verification for Python 3.10.18+20250918 downloads: - Add PYTHON_CHECKSUMS map with SHA-256 hashes for all supported platforms - Implement getPythonChecksum() to select platform-specific checksum - Pass checksum to downloadBinary() for verification during download - Checksums sourced from python-build-standalone release 20250918 Also update @socketsecurity/registry to use catalog version.
1 parent 3526c35 commit 662d3dd

File tree

3 files changed

+60
-3
lines changed

3 files changed

+60
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"@socketregistry/yocto-spinner": "1.0.24",
4141
"@socketsecurity/config": "3.0.1",
4242
"@socketsecurity/lib": "catalog:",
43-
"@socketsecurity/registry": "2.0.0",
43+
"@socketsecurity/registry": "catalog:",
4444
"@socketsecurity/sdk": "3.0.29",
4545
"@types/cmd-shim": "5.0.2",
4646
"@types/ink": "2.0.3",

packages/cli/src/utils/python/standalone.mts

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,24 @@ import { getErrorCause, InputError } from '../error/errors.mts'
5959

6060
import type { CResult } from '../../types.mjs'
6161

62+
/**
63+
* SHA-256 checksums for Python 3.10.18+20250918 install_only builds.
64+
* Retrieved from: https://github.com/astral-sh/python-build-standalone/releases/tag/20250918
65+
*/
66+
const PYTHON_CHECKSUMS: Record<string, string> = {
67+
__proto__: null,
68+
'aarch64-apple-darwin':
69+
'5f2a620c5278967c7fe666c9d41dc5d653c1829b3c26f62ece0d818e1a5ff9f8',
70+
'aarch64-unknown-linux-gnu':
71+
'16cb27d4d4d03cfb68d55d64e83a96aa3cd93c002c1de8ab7ddf3aa867c9e5f0',
72+
'x86_64-apple-darwin':
73+
'4ee44bf41d06626ad2745375d690679587c12d375e41a78f857a9660ce88e255',
74+
'x86_64-pc-windows-msvc':
75+
'7f8b19397a39188d07c68d83fd88b8da35ef1e007bdb066ed86169d60539f644',
76+
'x86_64-unknown-linux-gnu':
77+
'a6b9950cee5467d3a0a35473b3e848377912616668968627ba2254e5da4a1d1e',
78+
}
79+
6280
/**
6381
* Get the download URL for python-build-standalone based on platform and architecture.
6482
*
@@ -185,22 +203,58 @@ export async function checkSystemPython(): Promise<string | null> {
185203
}
186204
}
187205

206+
/**
207+
* Get the checksum for the current platform's Python build.
208+
* Returns the SHA-256 checksum from PYTHON_CHECKSUMS map.
209+
*/
210+
function getPythonChecksum(): string {
211+
const platform = os.platform()
212+
const arch = os.arch()
213+
214+
let platformTriple: string
215+
216+
if (platform === 'darwin') {
217+
platformTriple =
218+
arch === 'arm64' ? 'aarch64-apple-darwin' : 'x86_64-apple-darwin'
219+
} else if (platform === 'linux') {
220+
platformTriple =
221+
arch === 'arm64'
222+
? 'aarch64-unknown-linux-gnu'
223+
: 'x86_64-unknown-linux-gnu'
224+
} else if (platform === 'win32') {
225+
platformTriple = 'x86_64-pc-windows-msvc'
226+
} else {
227+
throw new InputError(`Unsupported platform: ${platform}`)
228+
}
229+
230+
const checksum = PYTHON_CHECKSUMS[platformTriple]
231+
if (!checksum) {
232+
throw new InputError(
233+
`No checksum available for platform: ${platformTriple}`,
234+
)
235+
}
236+
237+
return checksum
238+
}
239+
188240
/**
189241
* Download and extract Python from python-build-standalone using downloadBinary.
190242
* Uses downloadBinary for caching, checksum verification, and download management.
191243
*/
192244
async function downloadPython(pythonDir: string): Promise<void> {
193245
const url = getPythonStandaloneUrl()
194246
const tarballName = 'python-standalone.tar.gz'
247+
const checksum = getPythonChecksum()
195248

196249
// Ensure directory exists.
197250
await safeMkdir(pythonDir, { recursive: true })
198251

199252
try {
200-
// Use downloadBinary to download the tarball with caching (without execution).
253+
// Use downloadBinary to download the tarball with caching and checksum verification.
201254
const result = await downloadBinary({
202255
url,
203256
name: tarballName,
257+
checksum,
204258
})
205259

206260
// Extract the tarball to pythonDir.

pnpm-lock.yaml

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)