Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve critical vulnerability in helper script #486

Merged
merged 1 commit into from
Dec 6, 2024
Merged
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
31 changes: 20 additions & 11 deletions script/js/compare-rule-xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
* </rule>
*/

const fs = require("fs");
const libxmljs = require("libxmljs");
import * as fs from 'fs';
import { XmlDocument } from 'libxml2-wasm';

const [_, __, filePath1, filePath2, ruleFilePath] = process.argv;

Expand All @@ -60,37 +60,46 @@ if (!filePath1 || !filePath2 || !ruleFilePath) {
process.exit(1);
}

/**
* @param {string} filePath
*/
const getRuleIds = (filePath) => {
try {
return fs.readFileSync(filePath, "utf-8").split("\n");
} catch (e) {
} catch (/** @type {any}*/e) {
console.error(`Error reading ${filePath}: ${e.message}`);
process.exit(1);
}
};

/**
* @param {string} filePath
* @returns {[string, string]}
*/
const getFileStrFromPath = (filePath) => {
try {
return [filePath, fs.readFileSync(filePath, "utf-8")];
} catch (e) {
} catch (/** @type {any}*/e) {
console.error(`Error reading ${filePath}: ${e.message}`);
process.exit(1);
}
};

/**
* @returns {[string, libxmljs.Document]}
* @param {[string, string]} filePath
* @returns {[string, XmlDocument]}
*/
const getXMLFromFile = ([filePath, str]) => {
try {
return [filePath, libxmljs.parseXml(str)];
} catch (e) {}
console.log(`Error parsing ${filePath}: ${e.message}`);
process.exit(1);
return [filePath, XmlDocument.fromString(str)];
} catch (/** @type {any}*/e) {
console.log(`Error parsing ${filePath}: ${e.message}`);
process.exit(1);
}
};

/**
* @param {libxmljs.Document} doc
* @param {XmlDocument} doc
* @param {string} ruleId
*/
const getRuleNodeFromDoc = (doc, ruleId) => {
Expand Down Expand Up @@ -125,7 +134,7 @@ ruleIds.map((ruleId) => {
if (!rulesIn2.rule && !rulesIn1.rule) {
return console.log(`${ruleId} not found in either file`);
}
if (rulesIn2.rule.toString() !== rulesIn1.rule.toString()) {
if (rulesIn1 !== undefined && rulesIn1.rule !== undefined && rulesIn2 !== undefined && rulesIn2.rule !== undefined && rulesIn2.rule.toString() !== rulesIn1.rule.toString()) {
return console.log(
`${ruleId} has changed: \n${rulesIn1.path}:\n${rulesIn1.rule.toString()}\n${
rulesIn2.path
Expand Down
10 changes: 9 additions & 1 deletion script/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"type": "module",
"scripts": {
"check-types": "tsc --noEmit"
},
"dependencies": {
"libxmljs": "^0.19.10"
"libxml2-wasm": "^0.4.1"
},
"devDependencies": {
"@types/node": "^22.10.1",
"typescript": "^5.7.2"
}
}
20 changes: 20 additions & 0 deletions script/js/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"strict": true,
"noImplicitAny": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"strictBindCallApply": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"alwaysStrict": true,
"esModuleInterop": true,
"checkJs": true,
"allowJs": true,
"declaration": true,
"target": "ES2016",
"module": "ESNext",
"moduleResolution": "node"
},
"verbose": true
}
Loading
Loading