Compare commits

..
Author SHA1 Message Date
Zaid Humaimidi 944a690d96 1.2.15 2026-03-26 14:12:26 -07:00
Zaid Humaimidi e7facc3bba Changelog for v1.2.15 2026-03-26 14:10:18 -07:00
Zaid Humaimidi aa83b62064 Update dependencies 2026-03-26 13:50:37 -07:00
Zaid Humaimidi f9ee39dfd0 Fix device ID parsing regression in Mithril 2.3.8
Device IDs containing literal % characters (e.g., "202BC1-CODA%2D5519-000000")
are double-encoded in URLs. Mithril 2.3.8 incorrectly double-decodes route
parameters, corrupting device IDs with special characters.

Workaround: Extract device ID directly from window.location.hash and decode
once to get the correct value.

See: https://github.com/MithrilJS/mithril.js/issues/3064
2026-03-26 13:20:19 -07:00
Zaid Humaimidi 087b95388f Fix RCE vulnerability in /api/ping endpoint
This addresses a follow-up to CVE-2021-46704 where the host validation
could be bypassed via domainToASCII stripping path components.

Changes:
- Normalize host with domainToASCII before validation
- Add round-trip check with domainToUnicode to catch path injection
- Switch from exec to execFile to prevent shell injection
- Add -- separator to ping arguments

Credit: JuHwiSang for reporting this vulnerability
2026-03-25 15:00:00 -07:00
Zaid Humaimidi cc723c0b50 1.2.14 2026-03-12 14:26:22 -07:00
Zaid Humaimidi a2a6fd82f3 Changelog for v1.2.14 2026-03-12 14:25:25 -07:00
Zaid Humaimidi 729beba0ed Update dependencies 2026-03-12 12:38:03 -07:00
Zaid Humaimidi 1b14387aa2 Fix covers() for false and contradictions 2026-03-12 10:21:03 -07:00
Zaid Humaimidi 49cdd39617 Fix (de)serialization bug in VersionedMap 2025-02-12 19:05:08 -08:00
16 changed files with 3049 additions and 2783 deletions

No files matched your search

+15
View File
@@ -1,5 +1,20 @@
# Change Log # Change Log
## 1.2.15 (2026-03-26)
- Fix critical RCE vulnerability in /api/ping endpoint (follow-up to
CVE-2021-46704). Credit: JuHwiSang.
- Fix device IDs containing special characters (e.g., %) not being handled
correctly in the UI due to a regression in Mithril 2.3.8.
## 1.2.14 (2026-03-12)
- Prevent UI crash when a malformed URL is sent to the server.
- Fix potential edge-case bugs in expression evaluation and session
serialization.
## 1.2.13 (2024-06-06) ## 1.2.13 (2024-06-06)
- Increase connection timeout for UI and NBI from 30 to 120 seconds to avoid - Increase connection timeout for UI and NBI from 30 to 120 seconds to avoid
+4 -4
View File
@@ -2,13 +2,13 @@ import { PermissionSet, Expression } from "../types.ts";
import { evaluate, or } from "./expression/util.ts"; import { evaluate, or } from "./expression/util.ts";
export default class Authorizer { export default class Authorizer {
private declare permissionSets: PermissionSet[]; declare private permissionSets: PermissionSet[];
private declare validatorCache: WeakMap< declare private validatorCache: WeakMap<
any, any,
(mutationType, mutation, any) => boolean (mutationType, mutation, any) => boolean
>; >;
private declare hasAccessCache: Map<string, boolean>; declare private hasAccessCache: Map<string, boolean>;
private declare getFilterCache: Map<string, Expression>; declare private getFilterCache: Map<string, Expression>;
public constructor(permissionSets: PermissionSet[]) { public constructor(permissionSets: PermissionSet[]) {
this.permissionSets = permissionSets; this.permissionSets = permissionSets;
+3 -3
View File
@@ -9,8 +9,8 @@ const TWO = BI.BigInt(2);
const NEGATIVE_ONE = BI.BigInt(-1); const NEGATIVE_ONE = BI.BigInt(-1);
class Indeterminates { class Indeterminates {
public declare map: Map<string, number>; declare public map: Map<string, number>;
public declare sortedKeys: string[]; declare public sortedKeys: string[];
public constructor(str?: string) { public constructor(str?: string) {
this.map = new Map(); this.map = new Map();
@@ -98,7 +98,7 @@ function findGcd(a: BI.bigint, b: BI.bigint): BI.bigint {
} }
class Polynomial { class Polynomial {
public declare terms: Term[]; declare public terms: Term[];
public constructor(terms: Term[]) { public constructor(terms: Term[]) {
this.terms = terms; this.terms = terms;
+1 -1
View File
@@ -955,7 +955,7 @@ export function covers(expr1: Expression, expr2: Expression): boolean {
expr2 = normalize(expr2); expr2 = normalize(expr2);
if (!expr2) return true; if (!expr2) return true;
expr1 = normalize(expr1); expr1 = normalize(expr1);
if (!Array.isArray(expr1)) return !!expr1; if (!Array.isArray(expr1) && expr1) return true;
const synt1 = Clause.fromExpression(expr1); const synt1 = Clause.fromExpression(expr1);
const synt2 = Clause.fromExpression(expr2); const synt2 = Clause.fromExpression(expr2);
+3 -3
View File
@@ -1,9 +1,9 @@
import Path from "./path.ts"; import Path from "./path.ts";
export default class PathSet { export default class PathSet {
private declare lengthIndex: Set<Path>[]; declare private lengthIndex: Set<Path>[];
private declare fragmentIndex: Map<string, Set<Path>>[]; declare private fragmentIndex: Map<string, Set<Path>>[];
private declare stringIndex: Map<string, Path>; declare private stringIndex: Map<string, Path>;
public constructor() { public constructor() {
this.lengthIndex = []; this.lengthIndex = [];
+5 -5
View File
@@ -30,11 +30,11 @@ function legalChar(c: number): boolean {
} }
export default class Path { export default class Path {
public declare readonly segments: Segments; declare public readonly segments: Segments;
public declare readonly wildcard: number; declare public readonly wildcard: number;
public declare readonly alias: number; declare public readonly alias: number;
protected declare _string: string; declare protected _string: string;
protected declare _stringIndex: number[]; declare protected _stringIndex: number[];
protected static parseAliasValue( protected static parseAliasValue(
pattern: string, pattern: string,
+1 -1
View File
@@ -3,7 +3,7 @@ interface Instance {
} }
export default class InstanceSet { export default class InstanceSet {
private declare set: Set<Instance>; declare private set: Set<Instance>;
public constructor() { public constructor() {
this.set = new Set(); this.set = new Set();
+16 -7
View File
@@ -1,6 +1,6 @@
import { platform } from "node:os"; import { platform } from "node:os";
import { exec } from "node:child_process"; import { execFile } from "node:child_process";
import { domainToASCII } from "node:url"; import { domainToASCII, domainToUnicode } from "node:url";
export interface PingResult { export interface PingResult {
packetsTransmitted: number; packetsTransmitted: number;
@@ -16,9 +16,16 @@ function isValidHost(host: string): boolean {
// Valid chars in IPv4, IPv6, domain names // Valid chars in IPv4, IPv6, domain names
if (/^[a-zA-Z0-9\-.:[\]-]+$/.test(host)) return true; if (/^[a-zA-Z0-9\-.:[\]-]+$/.test(host)) return true;
const lowercase = host.toLowerCase();
const ascii = domainToASCII(lowercase);
// Check if input is an IDN convert to Punycode // Check if input is an IDN convert to Punycode
// Can't merge with above because domainToASCII doesn't accept IP addresses // Can't merge with above because domainToASCII doesn't accept IP addresses
return /^[a-zA-Z0-9\-.:[\]-]+$/.test(domainToASCII(host)); if (!/^[a-zA-Z0-9\-.:[\]-]+$/.test(ascii)) return false;
// Round-trip to ensure the original host matches its normalized form.
// This prevents bypasses where domainToASCII strips paths (e.g. "example.com/;cmd").
return lowercase === domainToUnicode(ascii);
} }
export function parsePing(osPlatform: string, stdout: string): PingResult { export function parsePing(osPlatform: string, stdout: string): PingResult {
@@ -73,24 +80,26 @@ export function ping(
): void { ): void {
// Validate input to prevent possible remote code execution // Validate input to prevent possible remote code execution
// Credit to Alex Hordijk for reporting this vulnerability // Credit to Alex Hordijk for reporting this vulnerability
// Credit to JuHwiSang for reporting a follow-up vulnerability
if (!isValidHost(host)) return callback(new Error("Invalid host")); if (!isValidHost(host)) return callback(new Error("Invalid host"));
host = host.replace("[", "").replace("]", ""); host = host.replace("[", "").replace("]", "");
let cmd: string; let args: string[];
switch (platform()) { switch (platform()) {
case "linux": case "linux":
cmd = `ping -w 1 -i 0.2 -c 3 ${host}`; args = ["-w", "1", "-i", "0.2", "-c", "3", "--", host];
break; break;
case "freebsd": case "freebsd":
// Send a single packet because on FreeBSD only superuser can send // Send a single packet because on FreeBSD only superuser can send
// packets that are only 200 ms apart. // packets that are only 200 ms apart.
cmd = `ping -t 1 -c 3 ${host}`; args = ["-t", "1", "-c", "3", "--", host];
break; break;
default: default:
return callback(new Error("Platform not supported")); return callback(new Error("Platform not supported"));
} }
exec(cmd, (err, stdout) => { // Use execFile instead of exec to avoid shell interpretation of the host
execFile("ping", args, (err, stdout) => {
if (err) return callback(err); if (err) return callback(err);
const parsed: PingResult = parsePing(platform(), stdout); const parsed: PingResult = parsePing(platform(), stdout);
return callback(err, parsed, stdout); return callback(err, parsed, stdout);
+9 -5
View File
@@ -7,10 +7,10 @@ interface Revisions<V> {
} }
export default class VersionedMap<K, V> { export default class VersionedMap<K, V> {
private declare _sizeDiff: number[]; declare private _sizeDiff: number[];
private declare _revision: number; declare private _revision: number;
private declare map: Map<K, (V | symbol)[]>; declare private map: Map<K, (V | symbol)[]>;
public declare dirty: number; declare public dirty: number;
public constructor() { public constructor() {
this._sizeDiff = [0]; this._sizeDiff = [0];
@@ -112,6 +112,8 @@ export default class VersionedMap<K, V> {
prev = v; prev = v;
} }
if (prev === NONEXISTENT && !res.delete) return null;
return res; return res;
} }
@@ -122,6 +124,8 @@ export default class VersionedMap<K, V> {
del, del,
); );
if (!mutations) return;
const revisions = []; const revisions = [];
let prev: V | symbol = NONEXISTENT; let prev: V | symbol = NONEXISTENT;
@@ -149,7 +153,7 @@ export default class VersionedMap<K, V> {
public *diff(): IterableIterator<[K, V, V]> { public *diff(): IterableIterator<[K, V, V]> {
for (const [key, revisions] of this.map) { for (const [key, revisions] of this.map) {
if (revisions.length === 1) continue; if (revisions.length <= 1) continue;
let first = revisions[0]; let first = revisions[0];
let last = revisions[revisions.length - 1]; let last = revisions[revisions.length - 1];
if (first === NONEXISTENT && last === NONEXISTENT) continue; if (first === NONEXISTENT && last === NONEXISTENT) continue;
+2894 -2718
View File
File diff suppressed because it is too large. Load diff
+24 -24
View File
@@ -1,6 +1,6 @@
{ {
"name": "genieacs", "name": "genieacs",
"version": "1.2.13", "version": "1.2.15",
"description": "A TR-069 Auto Configuration Server (ACS)", "description": "A TR-069 Auto Configuration Server (ACS)",
"repository": { "repository": {
"type": "git", "type": "git",
@@ -26,15 +26,15 @@
}, },
"dependencies": { "dependencies": {
"@breejs/later": "^4.2.0", "@breejs/later": "^4.2.0",
"@koa/bodyparser": "^5.1.1", "@koa/bodyparser": "^5.1.2",
"@koa/router": "^13.1.0", "@koa/router": "^13.1.1",
"bson": "^4.7.2", "bson": "^4.7.2",
"espresso-iisojs": "^1.0.8", "espresso-iisojs": "^1.0.8",
"iconv-lite": "^0.6.3", "iconv-lite": "^0.6.3",
"ipaddr.js": "^2.2.0", "ipaddr.js": "^2.3.0",
"jsonwebtoken": "^9.0.2", "jsonwebtoken": "^9.0.3",
"koa": "^2.15.3", "koa": "^2.16.4",
"koa-compress": "^5.1.0", "koa-compress": "^5.2.1",
"koa-jwt": "^4.0.3", "koa-jwt": "^4.0.3",
"koa-send": "^5.0.1", "koa-send": "^5.0.1",
"mongodb": "^4.16.0", "mongodb": "^4.16.0",
@@ -42,26 +42,26 @@
"seedrandom": "^3.0.5" "seedrandom": "^3.0.5"
}, },
"devDependencies": { "devDependencies": {
"@types/codemirror": "^5.60.15", "@types/codemirror": "^5.60.17",
"@types/jsonwebtoken": "^9.0.6", "@types/jsonwebtoken": "^9.0.10",
"@types/koa": "^2.15.0", "@types/koa": "^2.15.0",
"@types/koa-compress": "^4.0.6", "@types/koa-compress": "^4.0.7",
"@types/mithril": "^2.2.6", "@types/mithril": "^2.2.8",
"@types/node": "^20.14.2", "@types/node": "^20.19.37",
"@types/parsimmon": "^1.10.9", "@types/parsimmon": "^1.10.9",
"@types/seedrandom": "^3.0.8", "@types/seedrandom": "^3.0.8",
"@typescript-eslint/eslint-plugin": "^7.12.0", "@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.12.0", "@typescript-eslint/parser": "^7.18.0",
"codemirror": "^5.65.16", "codemirror": "^5.65.21",
"esbuild": "^0.25.0", "esbuild": "^0.27.4",
"eslint": "^8.57.0", "eslint": "^8.57.1",
"eslint-config-prettier": "^9.1.0", "eslint-config-prettier": "^9.1.2",
"mithril": "^2.2.2", "mithril": "^2.3.8",
"prettier": "^3.3.1", "prettier": "^3.8.1",
"sql.js": "^1.10.3", "sql.js": "^1.14.1",
"svgo": "^3.3.2", "svgo": "^3.3.3",
"typescript": "^5.4.5", "typescript": "^5.9.3",
"yaml": "^1.10.2" "yaml": "^1.10.3"
}, },
"engines": { "engines": {
"node": ">=12.13.0" "node": ">=12.13.0"
+35 -1
View File
@@ -1,7 +1,7 @@
import test from "node:test"; import test from "node:test";
import assert from "node:assert"; import assert from "node:assert";
import initSqlJs from "sql.js/dist/sql-asm.js"; import initSqlJs from "sql.js/dist/sql-asm.js";
import { minimize, unionDiff } from "../lib/common/expression/synth.ts"; import { covers, minimize, unionDiff } from "../lib/common/expression/synth.ts";
import { parse, stringify } from "../lib/common/expression/parser.ts"; import { parse, stringify } from "../lib/common/expression/parser.ts";
const STRING_VALUES = [null, "", "a", "ab", "ab10", "ab-10"]; const STRING_VALUES = [null, "", "a", "ab", "ab10", "ab-10"];
@@ -115,3 +115,37 @@ void test("unionDiff", async () => {
assert.strictEqual(setsEqual(res4, diffSet), true); assert.strictEqual(setsEqual(res4, diffSet), true);
} }
}); });
void test("covers", async () => {
assert.strictEqual(covers(false, false), true);
assert.strictEqual(covers(false, parse("decimal > 5 AND decimal < 3")), true);
assert.strictEqual(covers(parse("true"), parse("decimal > 0")), true);
assert.strictEqual(covers(parse("true"), parse("false")), true);
assert.strictEqual(covers(parse("false"), parse("false")), true);
assert.strictEqual(covers(parse("false"), parse("decimal > 0")), false);
assert.strictEqual(covers(parse("decimal >= 0"), parse("decimal > 0")), true);
assert.strictEqual(
covers(parse("decimal > 0"), parse("decimal >= 0")),
false,
);
const cases = [
["decimal >= 0", "decimal > 0"],
["decimal > 0", "decimal > 5"],
["string IS NOT NULL", "string = 'a'"],
["true", "decimal > 0"],
];
for (const [c1, c2] of cases) {
const res1 = await query(c1);
const res2 = await query(c2);
const coversResult = covers(parse(c1), parse(c2));
const actuallyCovers = Array.from(res2).every((r) => res1.has(r));
assert.strictEqual(
coversResult,
actuallyCovers,
`covers(${c1}, ${c2}) should match actual coverage`,
);
}
});
+2 -1
View File
@@ -11,7 +11,8 @@
"strictFunctionTypes": true, "strictFunctionTypes": true,
"isolatedModules": true, "isolatedModules": true,
"noEmit": true, "noEmit": true,
"allowImportingTsExtensions": true "allowImportingTsExtensions": true,
"skipLibCheck": true
}, },
"include": [ "include": [
"./bin/*.ts", "./bin/*.ts",
+7 -7
View File
@@ -4,13 +4,13 @@ type AutocompleteCallback = (
) => void; ) => void;
export default class Autocomplete { export default class Autocomplete {
private declare callback: AutocompleteCallback; declare private callback: AutocompleteCallback;
private declare element: HTMLInputElement; declare private element: HTMLInputElement;
private declare hideTimeout: NodeJS.Timeout; declare private hideTimeout: NodeJS.Timeout;
private declare visible: boolean; declare private visible: boolean;
private declare default: string; declare private default: string;
private declare selection: number; declare private selection: number;
private declare container: HTMLElement; declare private container: HTMLElement;
public constructor(className: string, callback: AutocompleteCallback) { public constructor(className: string, callback: AutocompleteCallback) {
this.callback = callback; this.callback = callback;
+1 -1
View File
@@ -79,7 +79,7 @@ export function structureConfig(config: Config[]): any {
if (idx >= 0 && idx < MAX_ARRAY_SIZE && String(idx) === key) { if (idx >= 0 && idx < MAX_ARRAY_SIZE && String(idx) === key) {
const pos = Math.floor(idx / MAX_BITS); const pos = Math.floor(idx / MAX_BITS);
if (!indexes[pos]) indexes[pos] = 0; if (!indexes[pos]) indexes[pos] = 0;
indexes[pos] |= 1 << idx % MAX_BITS; indexes[pos] |= 1 << (idx % MAX_BITS);
} else { } else {
indexes = []; indexes = [];
break; break;
+29 -2
View File
@@ -3,6 +3,29 @@ import { m } from "./components.ts";
import config from "./config.ts"; import config from "./config.ts";
import * as store from "./store.ts"; import * as store from "./store.ts";
// Workaround for Mithril 2.3.8 regression
// https://github.com/MithrilJS/mithril.js/issues/3064
function getPathParamFromHash(hash: string, prefix: string): string | null {
if (!hash.startsWith(prefix)) return null;
const pathWithQuery = hash.slice(prefix.length);
// Stop at query string or hash fragment (mirrors Mithril's parsePathname)
const queryIdx = pathWithQuery.indexOf("?");
const hashIdx = pathWithQuery.indexOf("#");
let pathEnd = pathWithQuery.length;
if (queryIdx >= 0) pathEnd = Math.min(pathEnd, queryIdx);
if (hashIdx >= 0) pathEnd = Math.min(pathEnd, hashIdx);
const rawPath = pathWithQuery.slice(0, pathEnd);
// Normalize: collapse slashes, remove trailing slash (matches Mithril)
const normalizedPath = rawPath.replace(/\/{2,}/g, "/").replace(/\/$/, "");
// Decode once (Mithril already decoded with decodeURIComponentSafe)
return decodeURIComponent(normalizedPath);
}
export function init( export function init(
args: Record<string, unknown>, args: Record<string, unknown>,
): Promise<Record<string, unknown>> { ): Promise<Record<string, unknown>> {
@@ -12,9 +35,13 @@ export function init(
); );
} }
const deviceId =
getPathParamFromHash(window.location.hash, "#!/devices/") ??
(args.id as string);
return Promise.resolve({ return Promise.resolve({
deviceId: args.id, deviceId: deviceId,
deviceFilter: ["=", ["PARAM", "DeviceID.ID"], args.id], deviceFilter: ["=", ["PARAM", "DeviceID.ID"], deviceId],
}); });
} }