Skip to content

Commit

Permalink
add checks about body, subpaths and headers
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvaroVega committed Oct 7, 2024
1 parent 103ce8b commit 80f368b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
5 changes: 3 additions & 2 deletions configAccessMatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ configAccessMatch.users = [

// Activity related with request which the following headers
configAccessMatch.headers = [
{ "Fiware-service": "smartcity" },
{ "fiware-service": "smartcity" },
{ "x-real-ip": "127.0.0.1" }
];

// Activity related with request including the following subpaths
configAccessMatch.subpath = [
configAccessMatch.subpaths = [
'/v1',
];

Expand Down
29 changes: 27 additions & 2 deletions lib/middleware/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,32 @@ function accountInfo(req, res, next) {

// CHeck here MATCH file patterns:
if (req.userName in configAccessMatch.users ) {
accessMsg += ' MATCHED USER';
accessMsg += ' MATCHED USER';
}
for (var header of configAccessMatch.headers) {
if ('fiware-service' in Object.keys(header)) {
if (req.service.includes(header['fiware-service'])) {
accessMsg += ' MATCHED HEADER Service';
}
} else if ('fiware-servicepath' in Object.keys(header)) {
if (req.subService.includes(header['fiware-servicepath'])) {
accessMsg += ' MATCHED HEADER SubService';
}
} else if ('x-real-ip' in Object.keys(header)) {
if (req.connection.remoteAddress.includes(header['x-real-ip'])) {
accessMsg += ' MATCHED HEADER Origin';
}
}
}
for (var subpath of configAccessMatch.subpaths) {
if (req.path.includes(subpath)) {
accessMsg += ' MATCHED SUBPATH ' + subpath;
}
}
for (var text of configAccessMatch.body) {
if (JSON.stringify(req.body).includes(text)) {
accessMsg += ' MATCHED BODY ' + text;
}
}

accessLogger.info(accessMsg +
Expand All @@ -237,7 +262,7 @@ function accountInfo(req, res, next) {
' | SubService=' + req.subService +
' | Action=' + req.action +
' | Path=' + req.path +
' | Body=' + JSON.stringify(req.body).slice(0, 100) +
' | Body=' + JSON.stringify(req.body).slice(0, 100) + // not all body
' | Date=' + new Date().toJSON());
});
}
Expand Down

0 comments on commit 80f368b

Please sign in to comment.