Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 9 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70472,6 +70472,15 @@ if (require.main === require.cache[eval('__filename')]) {
const os = __nccwpck_require__(857);

function normalizeVersionName(version) {
// The version is interpolated into the release download URL, and the downloaded
// archive is extracted and added to PATH. Reject anything that is not a plain tag
// name: a value containing "/" or ".." is normalized away by the URL parser and
// would point the download at an arbitrary repository, causing the runner to
// execute an attacker-supplied binary.
if (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(version) || version.includes("..")) {
throw new Error(`Invalid version input: '${version}'`);
}

const normalized = version.replace(/^nightly-[0-9a-f]{40}$/, "nightly");

// Check if the normalized version is a semver and format it accordingly
Expand Down
89 changes: 49 additions & 40 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,49 @@
const os = require("os");

function normalizeVersionName(version) {
const normalized = version.replace(/^nightly-[0-9a-f]{40}$/, "nightly");

// Check if the normalized version is a semver and format it accordingly
if (/^v?\d+\.\d+\.\d+$/.test(normalized)) {
// If it's missing the 'v' prefix, add it
const withV = normalized.startsWith("v") ? normalized : `v${normalized}`;
// Prepend "foundry-zksync-" to the tag
return `foundry-zksync-${withV}`;
}
return normalized;
}

function mapArch(arch) {
const mappings = {
x32: "386",
x64: "amd64",
};

return mappings[arch] || arch;
}

function getDownloadObject(version) {
const platform = os.platform();
const normalizedVersion = normalizeVersionName(version);
const filename = `${normalizedVersion.replaceAll("-", "_")}_${platform}_${mapArch(os.arch())}`;
const extension = platform === "win32" ? "zip" : "tar.gz";
const url = `https://github.com/matter-labs/foundry-zksync/releases/download/${normalizedVersion}/${filename}.${extension}`;

return {
url,
binPath: ".",
};
}

module.exports = {
getDownloadObject,
};
const os = require("os");

function normalizeVersionName(version) {
// The version is interpolated into the release download URL, and the downloaded
// archive is extracted and added to PATH. Reject anything that is not a plain tag
// name: a value containing "/" or ".." is normalized away by the URL parser and
// would point the download at an arbitrary repository, causing the runner to
// execute an attacker-supplied binary.
if (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(version) || version.includes("..")) {
throw new Error(`Invalid version input: '${version}'`);
}

const normalized = version.replace(/^nightly-[0-9a-f]{40}$/, "nightly");

// Check if the normalized version is a semver and format it accordingly
if (/^v?\d+\.\d+\.\d+$/.test(normalized)) {
// If it's missing the 'v' prefix, add it
const withV = normalized.startsWith("v") ? normalized : `v${normalized}`;
// Prepend "foundry-zksync-" to the tag
return `foundry-zksync-${withV}`;
}
return normalized;
}

function mapArch(arch) {
const mappings = {
x32: "386",
x64: "amd64",
};

return mappings[arch] || arch;
}

function getDownloadObject(version) {
const platform = os.platform();
const normalizedVersion = normalizeVersionName(version);
const filename = `${normalizedVersion.replaceAll("-", "_")}_${platform}_${mapArch(os.arch())}`;
const extension = platform === "win32" ? "zip" : "tar.gz";
const url = `https://github.com/matter-labs/foundry-zksync/releases/download/${normalizedVersion}/${filename}.${extension}`;

return {
url,
binPath: ".",
};
}

module.exports = {
getDownloadObject,
};