Sanitize inputs
This commit is contained in:
Родитель
51bb5eb99a
Коммит
ecf723239a
|
@ -37,10 +37,19 @@ function getCredentials(logger, registrySecrets, registriesCredentials, language
|
|||
return [];
|
||||
}
|
||||
// Parse and validate the credentials
|
||||
const parsed = JSON.parse(credentialsStr);
|
||||
const out = [];
|
||||
let parsed;
|
||||
try {
|
||||
parsed = JSON.parse(credentialsStr);
|
||||
}
|
||||
catch (error) {
|
||||
// Don't log the error since it might contain sensitive information.
|
||||
logger.error("Failed to parse the credentials data.");
|
||||
throw new Error("Invalid credentials format.");
|
||||
}
|
||||
let out = [];
|
||||
for (const e of parsed) {
|
||||
if (e.url === undefined && e.host === undefined) {
|
||||
// The proxy needs one of these to work. If both are defined, the url has the precedence.
|
||||
throw new Error("Invalid credentials - must specify host or url");
|
||||
}
|
||||
// Filter credentials based on language if specified. `type` is the registry type.
|
||||
|
@ -48,6 +57,12 @@ function getCredentials(logger, registrySecrets, registriesCredentials, language
|
|||
if (registryTypeForLanguage && e.type !== registryTypeForLanguage) {
|
||||
continue;
|
||||
}
|
||||
const isPrintable = (str) => {
|
||||
return str ? /^[\x20-\x7E]*$/.test(str) : true;
|
||||
};
|
||||
if (!isPrintable(e.type) || !isPrintable(e.host) || !isPrintable(e.url) || !isPrintable(e.username) || !isPrintable(e.password) || !isPrintable(e.token)) {
|
||||
throw new Error("Invalid credentials - fields must contain only printable characters");
|
||||
}
|
||||
out.push({
|
||||
type: e.type,
|
||||
host: e.host,
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"start-proxy.js","sourceRoot":"","sources":["../src/start-proxy.ts"],"names":[],"mappings":";;AA6BA,wCA+CC;AA5ED,2CAAsD;AAYtD,MAAM,yBAAyB,GAA6B;IAC1D,IAAI,EAAE,kBAAkB;IACxB,MAAM,EAAE,YAAY;IACpB,UAAU,EAAE,cAAc;IAC1B,MAAM,EAAE,cAAc;IACtB,IAAI,EAAE,iBAAiB;IACvB,IAAI,EAAE,gBAAgB;IACtB,oF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,CAAC;QAEF,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;YACzJ,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC,CAAC;QACzF,CAAC;QAED,GAAG,CAAC,IAAI,CAAC;YACP,IAAI,EAAE,CAAC,CAAC,IAAI;YACZ,IAAI,EAAE,CAAC,CAAC,IAAI;YACZ,GAAG,EAAE,CAAC,CAAC,GAAG;YACV,QAAQ,EAAE,CAAC,CAAC,QAAQ;YACpB,QAAQ,EAAE,CAAC,CAAC,QAAQ;YACpB,KAAK,EAAE,CAAC,CAAC,KAAK;SACf,CAAC,CAAC;IACL,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@ -78,4 +78,18 @@ const testing_utils_1 = require("./testing-utils");
|
|||
const credentials = startProxyExports.getCredentials((0, logging_1.getRunnerLogger)(true), undefined, credentialsInput, undefined);
|
||||
t.is(credentials.length, 3);
|
||||
});
|
||||
(0, ava_1.default)("getCredentials throws an error when non-printable characters are used", async (t) => {
|
||||
const invalidCredentials = [
|
||||
{ type: "nuget_feed", host: "1nuget.pkg.github.com", token: "abc\u0000" }, // Non-printable character in token
|
||||
{ type: "nuget_feed", host: "2nuget.pkg.github.com\u0001" }, // Non-printable character in host
|
||||
{ type: "nuget_feed", host: "3nuget.pkg.github.com", password: "ghi\u0002" }, // Non-printable character in password
|
||||
{ type: "nuget_feed", host: "4nuget.pkg.github.com", password: "ghi\x00" }, // Non-printable character in password
|
||||
];
|
||||
for (const invalidCredential of invalidCredentials) {
|
||||
const credentialsInput = Buffer.from(JSON.stringify([invalidCredential])).toString("base64");
|
||||
t.throws(() => startProxyExports.getCredentials((0, logging_1.getRunnerLogger)(true), undefined, credentialsInput, undefined), {
|
||||
message: "Invalid credentials - fields must contain only printable characters",
|
||||
});
|
||||
}
|
||||
});
|
||||
//# sourceMappingURL=start-proxy.test.js.map
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"start-proxy.test.js","sourceRoot":"","sources":["../src/start-proxy.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAAuB;AAEvB,uCAA4C;AAC5C,iEAAmD;AACnD,mDAA6C;AAE7C,IAAA,0BAAU,EAAC,aAAI,CAAC,CAAC;AAEjB,IAAA,aAAI,EAAC,mEAAmE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IACpF,MAAM,mBAAmB,GAAG,MAAM,CAAC,IAAI,CACrC,IAAI,CAAC,SAAS,CAAC;QACb,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,oBAAoB,EAAE,KAAK,EAAE,KAAK,EAAE;KACnE,CAAC,CACH,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACrB,MAAM,eAAe,GAAG,IAAI,CAAC,SAAS,CAAC;QACrC,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,oBAAoB,EAAE,KAAK,EAAE,KAAK,EAAE;KACnE,CAAC,CAAC;IAEH,MAAM,WAAW,GAAG,iBAAiB,CAAC,cAAc,CAClD,IAAA,yBAAe,EAAC,IAAI,CAAC,EACrB,eAAe,EACf,mBAAmB,EACnB,SAAS,CACV,CAAC;IACF,CAAC,CAAC,EAAE,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAC5B,CAAC,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,oBAAoB,CAAC,CAAC;AAClD,CAAC,CAAC,CAAC;AAEH,IAAA,aAAI,EAAC,kEAAkE,EAAE,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IAAA,aAAI,EAAC,uEAAuE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IACtF,MAAM,kBAAkB,GAAG;QACzB,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,uBAAuB,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,mCAAmC;QAC9G,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,6BAA6B,EAAE,EAAE,kCAAkC;QAC/F,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,uBAAuB,EAAE,QAAQ,EAAE,WAAW,EAAE,EAAE,sCAAsC;QACpH,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,uBAAuB,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,sCAAsC;KACnH,CAAC;IAEF,KAAK,MAAM,iBAAiB,IAAI,kBAAkB,EAAE,CAAC;QACnD,MAAM,gBAAgB,GAAG,MAAM,CAAC,IAAI,CAClC,IAAI,CAAC,SAAS,CAAC,CAAC,iBAAiB,CAAC,CAAC,CACpC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAErB,CAAC,CAAC,MAAM,CACN,GAAG,EAAE,CACH,iBAAiB,CAAC,cAAc,CAC9B,IAAA,yBAAe,EAAC,IAAI,CAAC,EACrB,SAAS,EACT,gBAAgB,EAChB,SAAS,CACV,EACH;YACE,OAAO,EAAE,qEAAqE;SAC/E,CACF,CAAC;IACJ,CAAC;AACH,CAAC,CAAC,CAAC"}
|
|
@ -80,3 +80,31 @@ test("getCredentials returns all credentials when no language specified", async
|
|||
);
|
||||
t.is(credentials.length, 3);
|
||||
});
|
||||
|
||||
test("getCredentials throws an error when non-printable characters are used", async (t) => {
|
||||
const invalidCredentials = [
|
||||
{ type: "nuget_feed", host: "1nuget.pkg.github.com", token: "abc\u0000" }, // Non-printable character in token
|
||||
{ type: "nuget_feed", host: "2nuget.pkg.github.com\u0001" }, // Non-printable character in host
|
||||
{ type: "nuget_feed", host: "3nuget.pkg.github.com", password: "ghi\u0002" }, // Non-printable character in password
|
||||
{ type: "nuget_feed", host: "4nuget.pkg.github.com", password: "ghi\x00" }, // Non-printable character in password
|
||||
];
|
||||
|
||||
for (const invalidCredential of invalidCredentials) {
|
||||
const credentialsInput = Buffer.from(
|
||||
JSON.stringify([invalidCredential]),
|
||||
).toString("base64");
|
||||
|
||||
t.throws(
|
||||
() =>
|
||||
startProxyExports.getCredentials(
|
||||
getRunnerLogger(true),
|
||||
undefined,
|
||||
credentialsInput,
|
||||
undefined,
|
||||
),
|
||||
{
|
||||
message: "Invalid credentials - fields must contain only printable characters",
|
||||
},
|
||||
);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -51,10 +51,19 @@ export function getCredentials(
|
|||
}
|
||||
|
||||
// Parse and validate the credentials
|
||||
const parsed = JSON.parse(credentialsStr) as Credential[];
|
||||
const out: Credential[] = [];
|
||||
let parsed: Credential[];
|
||||
try {
|
||||
parsed = JSON.parse(credentialsStr) as Credential[];
|
||||
} catch (error) {
|
||||
// Don't log the error since it might contain sensitive information.
|
||||
logger.error("Failed to parse the credentials data.");
|
||||
throw new Error("Invalid credentials format.");
|
||||
}
|
||||
|
||||
let out: Credential[] = [];
|
||||
for (const e of parsed) {
|
||||
if (e.url === undefined && e.host === undefined) {
|
||||
// The proxy needs one of these to work. If both are defined, the url has the precedence.
|
||||
throw new Error("Invalid credentials - must specify host or url");
|
||||
}
|
||||
|
||||
|
@ -64,6 +73,15 @@ export function getCredentials(
|
|||
continue;
|
||||
}
|
||||
|
||||
|
||||
const isPrintable = (str: string | undefined): boolean => {
|
||||
return str ? /^[\x20-\x7E]*$/.test(str) : true;
|
||||
};
|
||||
|
||||
if (!isPrintable(e.type) || !isPrintable(e.host) || !isPrintable(e.url) || !isPrintable(e.username) || !isPrintable(e.password) || !isPrintable(e.token)) {
|
||||
throw new Error("Invalid credentials - fields must contain only printable characters");
|
||||
}
|
||||
|
||||
out.push({
|
||||
type: e.type,
|
||||
host: e.host,
|
||||
|
|
Загрузка…
Ссылка в новой задаче