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

Fix resource path pattern matching #132

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
29 changes: 13 additions & 16 deletions apikeys/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ var requestLib = require("request");
var _ = require("lodash");

const PRIVATE_JWT_VALUES = ["application_name", "client_id", "api_product_list", "iat", "exp"];
const SUPPORTED_DOUBLE_ASTERIK_PATTERN = "**";
const SUPPORTED_SINGLE_ASTERIK_PATTERN = "*";
const SUPPORTED_DOUBLE_ASTERISK_PATTERN = "**";
const SUPPORTED_SINGLE_ASTERISK_PATTERN = "*";
// const SUPPORTED_SINGLE_FORWARD_SLASH_PATTERN = "/"; // ?? this has yet to be used in any module.

const acceptAlg = ["RS256"];
Expand Down Expand Up @@ -258,23 +258,20 @@ const checkIfAuthorized = module.exports.checkIfAuthorized = function checkIfAut
if (apiproxy.endsWith("/") && !urlPath.endsWith("/")) {
urlPath = urlPath + "/";
}

if (apiproxy.includes(SUPPORTED_DOUBLE_ASTERIK_PATTERN)) {
const regex = apiproxy.replace(/\*\*/gi, ".*")
matchesProxyRules = urlPath.match(regex)
let regex = apiproxy;
if (apiproxy.includes(SUPPORTED_DOUBLE_ASTERISK_PATTERN)) {
regex = regex.replace(/\*\*/gi, ".+");
}
if (apiproxy.includes(SUPPORTED_SINGLE_ASTERISK_PATTERN)) {
regex = regex.replace(/\*/gi, "[^/]+");
}
if (regex !== apiproxy) {
regex = "^" + regex + "$";
matchesProxyRules = urlPath.match(regex) !== null;
} else {
if (apiproxy.includes(SUPPORTED_SINGLE_ASTERIK_PATTERN)) {
const regex = apiproxy.replace(/\*/gi, "[^/]+");
matchesProxyRules = urlPath.match(regex)
} else {
// if(apiproxy.includes(SUPPORTED_SINGLE_FORWARD_SLASH_PATTERN)){
// }
matchesProxyRules = urlPath === apiproxy;

}
matchesProxyRules = urlPath === apiproxy;
}
})

} else {
matchesProxyRules = true
}
Expand Down
8 changes: 4 additions & 4 deletions lib/basicAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ map.setup({
//
const acceptAlg = ['RS256'];

const SUPPORTED_DOUBLE_ASTERIK_PATTERN = "**";
const SUPPORTED_SINGLE_ASTERIK_PATTERN = "*";
const SUPPORTED_DOUBLE_ASTERISK_PATTERN = "**";
const SUPPORTED_SINGLE_ASTERISK_PATTERN = "*";
//const SUPPORTED_SINGLE_FORWARD_SLASH_PATTERN = "/";

const AUTH_HEADER_REGEX = /Bearer (.+)/;
Expand Down Expand Up @@ -412,11 +412,11 @@ class BasicAuthorizerPlugin {
urlPath = urlPath + "/";
}

if ( apiproxy.includes(SUPPORTED_DOUBLE_ASTERIK_PATTERN) ) {
if ( apiproxy.includes(SUPPORTED_DOUBLE_ASTERISK_PATTERN) ) {
const regex = apiproxy.replace(/\*\*/gi, ".*")
return(urlPath.match(regex) !== null )
} else {
if ( apiproxy.includes(SUPPORTED_SINGLE_ASTERIK_PATTERN) ) {
if ( apiproxy.includes(SUPPORTED_SINGLE_ASTERISK_PATTERN) ) {
const regex = apiproxy.replace(/\*/gi, "[^/]+");
return(urlPath.match(regex) !== null )
} else {
Expand Down
29 changes: 13 additions & 16 deletions oauth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ var _ = require('lodash');

const authHeaderRegex = /Bearer (.+)/;
const PRIVATE_JWT_VALUES = ['application_name', 'client_id', 'api_product_list', 'iat', 'exp'];
const SUPPORTED_DOUBLE_ASTERIK_PATTERN = "**";
const SUPPORTED_SINGLE_ASTERIK_PATTERN = "*";
const SUPPORTED_DOUBLE_ASTERISK_PATTERN = "**";
const SUPPORTED_SINGLE_ASTERISK_PATTERN = "*";
// const SUPPORTED_SINGLE_FORWARD_SLASH_PATTERN = "/";

const acceptAlg = ['RS256'];
Expand Down Expand Up @@ -384,23 +384,20 @@ const checkIfAuthorized = module.exports.checkIfAuthorized = function checkIfAut
if (apiproxy.endsWith("/") && !urlPath.endsWith("/")) {
urlPath = urlPath + "/";
}

if (apiproxy.includes(SUPPORTED_DOUBLE_ASTERIK_PATTERN)) {
const regex = apiproxy.replace(/\*\*/gi, ".*")
matchesProxyRules = urlPath.match(regex)
let regex = apiproxy;
if (apiproxy.includes(SUPPORTED_DOUBLE_ASTERISK_PATTERN)) {
regex = regex.replace(/\*\*/gi, ".+");
}
if (apiproxy.includes(SUPPORTED_SINGLE_ASTERISK_PATTERN)) {
regex = regex.replace(/\*/gi, "[^/]+");
}
if (regex !== apiproxy) {
regex = "^" + regex + "$";
matchesProxyRules = urlPath.match(regex) !== null;
} else {
if (apiproxy.includes(SUPPORTED_SINGLE_ASTERIK_PATTERN)) {
const regex = apiproxy.replace(/\*/gi, "[^/]+");
matchesProxyRules = urlPath.match(regex)
} else {
// if(apiproxy.includes(SUPPORTED_SINGLE_FORWARD_SLASH_PATTERN)){
// }
matchesProxyRules = urlPath === apiproxy;

}
matchesProxyRules = urlPath === apiproxy;
}
})

} else {
matchesProxyRules = true
}
Expand Down
29 changes: 13 additions & 16 deletions oauthv2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ var _ = require('lodash');

const authHeaderRegex = /Bearer (.+)/;
const PRIVATE_JWT_VALUES = ['application_name', 'client_id', 'api_product_list', 'iat', 'exp'];
const SUPPORTED_DOUBLE_ASTERIK_PATTERN = "**";
const SUPPORTED_SINGLE_ASTERIK_PATTERN = "*";
const SUPPORTED_DOUBLE_ASTERISK_PATTERN = "**";
const SUPPORTED_SINGLE_ASTERISK_PATTERN = "*";
//const SUPPORTED_SINGLE_FORWARD_SLASH_PATTERN = "/";

const acceptAlg = ['RS256'];
Expand Down Expand Up @@ -249,23 +249,20 @@ const checkIfAuthorized = module.exports.checkIfAuthorized = function checkIfAut
if (apiproxy.endsWith("/") && !urlPath.endsWith("/")) {
urlPath = urlPath + "/";
}

if (apiproxy.includes(SUPPORTED_DOUBLE_ASTERIK_PATTERN)) {
const regex = apiproxy.replace(/\*\*/gi, ".*")
matchesProxyRules = urlPath.match(regex)
let regex = apiproxy;
if (apiproxy.includes(SUPPORTED_DOUBLE_ASTERISK_PATTERN)) {
regex = regex.replace(/\*\*/gi, ".+");
}
if (apiproxy.includes(SUPPORTED_SINGLE_ASTERISK_PATTERN)) {
regex = regex.replace(/\*/gi, "[^/]+");
}
if (regex !== apiproxy) {
regex = "^" + regex + "$";
matchesProxyRules = urlPath.match(regex) !== null;
} else {
if (apiproxy.includes(SUPPORTED_SINGLE_ASTERIK_PATTERN)) {
const regex = apiproxy.replace(/\*/gi, "[^/]+");
matchesProxyRules = urlPath.match(regex)
} else {
// if(apiproxy.includes(SUPPORTED_SINGLE_FORWARD_SLASH_PATTERN)){
// }
matchesProxyRules = urlPath === apiproxy;

}
matchesProxyRules = urlPath === apiproxy;
}
})

} else {
matchesProxyRules = true
}
Expand Down