Skip to content

Commit ac73940

Browse files
authored
Properly escape and quote git tag names before passing it as shell parameter (#1065)
* add shescape library and properly escape and quote tag name before passing it to a shell * add mising @param
1 parent c6ed30f commit ac73940

3 files changed

Lines changed: 6 additions & 1 deletion

File tree

lib/resolveExtension.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ const readVSIXPackage = require("@vscode/vsce/out/zip").readVSIXPackage;
66
const download = require("download");
77
const exec = require("./exec");
88
const { repoPath } = require("./constants");
9+
const shescape = require("shescape");
910

1011
const token = process.env.GITHUB_TOKEN;
1112
if (!token) {
1213
console.warn("GITHUB_TOKEN env var is not set. Skipping lookup from releases");
1314
}
1415
const octokit = new Octokit({ auth: token });
1516

17+
const shellEscape = new shescape.Shescape({ shell: true });
18+
1619
/**
1720
*
1821
* @param {Readonly<import('../types').Extension>} extension
@@ -85,7 +88,7 @@ exports.resolveExtension = async function ({ id, repository, location }, ms) {
8588
*/
8689
async function resolveVersion(ref) {
8790
try {
88-
await exec(`git reset --hard ${ref} --quiet`, { cwd: repoPath, quiet: true });
91+
await exec(`git reset --hard ${shellEscape.quote(ref)} --quiet`, { cwd: repoPath, quiet: true });
8992
const manifest = JSON.parse(await fs.promises.readFile(packagePath, "utf-8"));
9093
if (`${manifest.publisher}.${manifest.name}`.toLowerCase() !== id.toLowerCase()) {
9194
return undefined;

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"ovsx": "latest",
4545
"prettier": "^3.2.5",
4646
"semver": "^7.1.3",
47+
"shescape": "^2.1.7",
4748
"xml2js": "^0.6.2",
4849
"yauzl-promise": "^4.0.0"
4950
},

scripts/publish-extension.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ async function bufferStream(stream) {
3434
*
3535
* @param {string} packagePath
3636
* @param {(name: string) => boolean} filter
37+
* @param {boolean} unique
3738
* @returns {Promise<Map<string, Buffer>>}
3839
*/
3940
async function readZip(packagePath, filter, unique) {

0 commit comments

Comments
 (0)