From 0fc805f12d354b7981f102734ad432cf3eb3a7e0 Mon Sep 17 00:00:00 2001 From: C-3PO Date: Sun, 4 Nov 2018 17:06:31 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Be=20more=20explicit=20in?= =?UTF-8?q?=20RegExp=20parsing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cdn/funcs/resolveDns.ts | 2 +- src/ssn/verify/verifyPatchmanifest.ts | 10 +++++----- src/ssn/verify/verifySolidpkg.ts | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cdn/funcs/resolveDns.ts b/src/cdn/funcs/resolveDns.ts index b5e89d7..3392468 100644 --- a/src/cdn/funcs/resolveDns.ts +++ b/src/cdn/funcs/resolveDns.ts @@ -37,7 +37,7 @@ const assert = (condition: boolean) => { if (!condition) { console.warn('Assert async function resolveDns(domain: string): Promise { return new Promise((resolve) => { //check given string for correctness to prevent injection attacks - if (!domain.match(/^[a-z0-9]+([-.]{1}[a-z0-9]+)*\.[a-z]{2,3}$/)) { return resolve([]); } + if (domain.match(/^[a-z0-9]+(?:[-.]{1}[a-z0-9]+)*\.[a-z]{2,3}$/) === null) { return resolve([]); } //Check Level3/North_America separately if (domain !== 'cdn-patch.swtor.com') { diff --git a/src/ssn/verify/verifyPatchmanifest.ts b/src/ssn/verify/verifyPatchmanifest.ts index fac5842..3582898 100644 --- a/src/ssn/verify/verifyPatchmanifest.ts +++ b/src/ssn/verify/verifyPatchmanifest.ts @@ -55,7 +55,7 @@ export default function verifyPatchmanifest(manifestFile: xmlJs.Element, product if (RequiredRelease.type !== 'element' || RequiredRelease.name !== 'RequiredRelease' || RequiredRelease.attributes !== undefined || RequiredRelease.elements === undefined) { throw new Error('Expected RequiredRelease element.'); } - if (RequiredRelease.elements.length !== 1 || RequiredRelease.elements[0].type !== 'text' || typeof RequiredRelease.elements[0].text !== 'string' || String(RequiredRelease.elements[0].text).match(/^(0|[1-9][0-9]*)$/) === null) { + if (RequiredRelease.elements.length !== 1 || RequiredRelease.elements[0].type !== 'text' || typeof RequiredRelease.elements[0].text !== 'string' || String(RequiredRelease.elements[0].text).match(/^(?:0|[1-9][0-9]*)$/) === null) { throw new Error('Expected integer in RequiredRelease element.'); } @@ -107,7 +107,7 @@ export default function verifyPatchmanifest(manifestFile: xmlJs.Element, product } //0 const Id = Release.elements[0]; - if (Id.type !== 'element' || Id.name !== 'Id' || Id.attributes !== undefined || Id.elements === undefined || Id.elements.length !== 1 || Id.elements[0].type !== 'text' || typeof Id.elements[0].text !== 'string' || String(Id.elements[0].text).match(/^(0|[1-9][0-9]*)$/) === null) { + if (Id.type !== 'element' || Id.name !== 'Id' || Id.attributes !== undefined || Id.elements === undefined || Id.elements.length !== 1 || Id.elements[0].type !== 'text' || typeof Id.elements[0].text !== 'string' || String(Id.elements[0].text).match(/^(?:0|[1-9][0-9]*)$/) === null) { throw new Error('Expected Id element.'); } //53678f8057e52896a8145dca5c188ab3f24fa55f @@ -138,7 +138,7 @@ export default function verifyPatchmanifest(manifestFile: xmlJs.Element, product throw new Error('Expected From element.'); } const fromNum = From.elements[0].text; - if (String(fromNum).match(/^(-1|0|[1-9][0-9]*)$/) === null) { + if (String(fromNum).match(/^(?:-1|0|[1-9][0-9]*)$/) === null) { throw new Error(`Expected From element to be a number but it was ${fromNum}.`); } //285 @@ -147,7 +147,7 @@ export default function verifyPatchmanifest(manifestFile: xmlJs.Element, product throw new Error('Expected To element.'); } const toNum = To.elements[0].text; - if (String(toNum).match(/^(0|[1-9][0-9]*)$/) === null) { + if (String(toNum).match(/^(?:0|[1-9][0-9]*)$/) === null) { throw new Error(`Expected To element to be a number but it was ${toNum}.`); } //TODO: check if From and To are valid relations @@ -184,7 +184,7 @@ export default function verifyPatchmanifest(manifestFile: xmlJs.Element, product const valueName = String(Value.elements[0].text); switch (keyName) { case 'SSN_VERSION': - if (!valueName.match(/^[0-9](\.[0-9])+$/)) { + if (valueName.match(/^[0-9](?:\.[0-9])+$/) === null) { throw new Error(`Expected valid Value for Key "SSN_VERSION" in patch ${fromNum}to${toNum} but it was "${valueName}".`); } break; diff --git a/src/ssn/verify/verifySolidpkg.ts b/src/ssn/verify/verifySolidpkg.ts index f50a5fe..2582535 100644 --- a/src/ssn/verify/verifySolidpkg.ts +++ b/src/ssn/verify/verifySolidpkg.ts @@ -6,7 +6,7 @@ export default function verifySolidpkg(file: ISolid, { product, from, to }: {pro throw new Error(`Expected creation date to be a number but it was "${file['creation date']}".`); } //used by most .solidpkg files - const announceGeneral = /^http:\/\/Tracker22\.[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}\.automated\.(tel\.swtor\.com|ssntracker\.int):80\/$/; + const announceGeneral = /^http:\/\/Tracker22\.[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}\.automated\.(?:tel\.swtor\.com|ssntracker\.int):80\/$/; //used by retailclient_swtor_-1to0 const announceRetailclientSwtor = /^http:\/\/Tracker14\.[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}\.automated\.snxd\.com:2500\/$/; if (file.announce.match(announceGeneral) === null && file.announce.match(announceRetailclientSwtor) === null) {