YellowSquare now no longer sets authType and remoteUser JSGI properties, when 401 code is not specified in SVR.JS configuration.

This commit is contained in:
Dorian Niemiec 2024-02-07 01:25:32 +01:00
parent 45139795f5
commit f019e845b7

View file

@ -56,12 +56,41 @@ class ErrorStream extends stream.Writable {
function Mod() {} function Mod() {}
Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, ext, uobject, search, defaultpage, users, page404, head, foot, fd, elseCallback, configJSON, callServerError, getCustomHeaders, origHref, redirect, parsePostData) { Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, ext, uobject, search, defaultpage, users, page404, head, foot, fd, elseCallback, configJSON, callServerError, getCustomHeaders, origHref, redirect, parsePostData, authUser) {
return function () { return function () {
if (!configJSON) { if (!configJSON) {
configJSON = configJSONS; configJSON = configJSONS;
} }
function checkIfThereIsA401Rule() {
var actually401 = false;
function createRegex(regex) {
var regexObj = regex.split("/");
if (regexObj.length == 0) throw new Error("Invalid regex!");
var modifiers = regexObj.pop();
regexObj.shift();
var searchString = regexObj.join("/");
return new RegExp(searchString, modifiers);
}
if(configJSON.nonStandardCodes) {
configJSON.nonStandardCodes.every(function (nonscode) {
if (nonscode.scode == 401) {
if (nonscode.regex && (req.url.match(createRegex(nonscode.regex)) || href.match(createRegex(nonscode.regex)))) {
actually401 = true;
return true;
} else if (nonscode.url && (nonStandardCodes[i].url == href || (os.platform() == "win32" && nonStandardCodes[i].url.toLowerCase() == href.toLowerCase()))) {
actually401 = true;
return true;
}
}
return false;
});
}
return actually401;
}
if (!getCustomHeaders) { if (!getCustomHeaders) {
var bheaders = JSON.parse(JSON.stringify(configJSON.customHeaders)); var bheaders = JSON.parse(JSON.stringify(configJSON.customHeaders));
} else { } else {
@ -141,7 +170,7 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e
} }
} }
function executeJSGIWithReqObj(a, b, req, res, pubip, port, software, dh) { function executeJSGIWithReqObj(a, b, req, res, pubip, port, software, dh, user) {
// Function to set up request object and execute JSGI scripts // Function to set up request object and execute JSGI scripts
var inputStream = new RequestBodyStream(req); var inputStream = new RequestBodyStream(req);
var errorStream = new ErrorStream(); var errorStream = new ErrorStream();
@ -175,7 +204,12 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e
jsgiRequestObject.remotePort = req.socket.remotePort; jsgiRequestObject.remotePort = req.socket.remotePort;
} }
if (req.headers.authorization) { if (typeof user != "undefined") {
if (user !== null) {
if (req.headers.authorization) jsgiRequestObject.authType = req.headers.authorization.split(" ")[0];
jsgiRequestObject.remoteUser = user;
}
} else if (req.headers.authorization && (typeof checkIfThereIsA401Rule == "undefined" || checkIfThereIsA401Rule())) {
jsgiRequestObject.authType = req.headers.authorization.split(" ")[0]; jsgiRequestObject.authType = req.headers.authorization.split(" ")[0];
if (jsgiRequestObject.authType == "Basic") { if (jsgiRequestObject.authType == "Basic") {
var remoteCred = req.headers.authorization.split(" ")[1]; var remoteCred = req.headers.authorization.split(" ")[1];
@ -226,7 +260,8 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e
process.version + process.version +
") YellowSquare/" + ") YellowSquare/" +
version, version,
bheaders bheaders,
authUser
); );
} catch (ex) { } catch (ex) {
if (!callServerError) { if (!callServerError) {
@ -301,7 +336,8 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e
process.version + process.version +
") YellowSquare/" + ") YellowSquare/" +
version, version,
bheaders bheaders,
authUser
); );
} catch (ex) { } catch (ex) {
if (!callServerError) { if (!callServerError) {