New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

hyperswitch

Package Overview
Dependencies
Maintainers
4
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hyperswitch - npm Package Compare versions

Comparing version 0.3.4 to 0.3.5

lib/filters/header_match.js

51

lib/auth.js

@@ -123,53 +123,2 @@ "use strict";

};
},
header_match: function(definition) {
var errorMessage = definition['x-error-message']
|| 'This client is not allowed to use the endpoint';
var whitelistMap = {};
Object.keys(definition['x-whitelists']).forEach(function(whitelistName) {
whitelistMap[whitelistName]
= constructInternalRequestRegex(definition['x-whitelists'][whitelistName]);
});
return {
prepareRequest: function() {
},
checkPermissions: function(hyper, req, permissions) {
if (hyper._rootReq.uri === '#internal-startup') {
// Skip a check on requests made by HyperSwitch during startup
return;
}
permissions.forEach(function(requirementDefinition) {
// Check if requirement is limited to some method
if (requirementDefinition.method
&& requirementDefinition.method !== req.method) {
return;
}
var headerMatchRequirement = requirementDefinition.value;
var headerName = headerMatchRequirement.header;
var headerValue = req.headers && req.headers[headerName]
|| hyper._rootReq.headers && hyper._rootReq.headers[headerName];
headerMatchRequirement.patterns.forEach(function(patternName) {
if (!whitelistMap[patternName]) {
throw new Error('Invalid spec. ' +
'Unknown client ip whitelist name: ' + patternName);
}
if (!whitelistMap[patternName].test(headerValue)) {
throw new HTTPError({
status: 403,
body: {
type: 'forbidden',
title: 'Access to resource denied',
description: errorMessage
}
});
}
});
});
}
};
}

@@ -176,0 +125,0 @@ };

48

lib/hyperswitch.js

@@ -284,4 +284,4 @@ 'use strict';

// Special handling for https? requests
if (req.uri.constructor === String && /^https?:\/\//.test(req.uri)
|| req.uri.urlObj) {
var host = req.uri.constructor === String ? req.uri : req.uri.protoHost;
if (/^https?:\/\//.test(host)) {
return self.defaultWebRequestHandler(req);

@@ -296,28 +296,28 @@ }

// Look up the route in the tree.
var match = this._priv.router.route(childReq.uri);
var methods = match && match.value && match.value.methods;
var handler = methods && (
(self._rootReq && self._rootReq.method === 'head' && methods.head)
|| methods[childReq.method]
|| methods.all);
if (!handler &&
(req.method === 'head'
|| self._rootReq && self._rootReq.method === 'head')) {
handler = methods && methods.get;
}
if (match && !handler
&& childReq.method === 'get'
&& childReq.uri.path[childReq.uri.path.length - 1] === '') {
// A GET for an URL that ends with /: return a default listing
if (!match.value) { match.value = {}; }
if (!match.value.path) { match.value.path = '_defaultListingHandler'; }
handler = function(hyper, req) {
return self.defaultListingHandler(match, hyper, req);
};
}
var handler;
if (match) {
childReq.params = match.params;
self._checkInternalApiRequest(childReq);
// Find a handler.
var methods = match.value && match.value.methods || {};
handler = methods[childReq.method] || methods.all;
if (!handler
&& (childReq.method === 'head'
|| self._rootReq && self._rootReq.method === 'head')) {
handler = methods && methods.get;
}
if (!handler
&& childReq.method === 'get'
&& childReq.uri.path[childReq.uri.path.length - 1] === '') {
// A GET for an URL that ends with /: return a default listing
if (!match.value) { match.value = {}; }
if (!match.value.path) { match.value.path = '_defaultListingHandler'; }
handler = function(hyper, req) {
return self.defaultListingHandler(match, hyper, req);
};
}
}

@@ -324,0 +324,0 @@

{
"name": "hyperswitch",
"version": "0.3.4",
"version": "0.3.5",
"description": "REST API creation framework",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -51,2 +51,33 @@ "use strict";

it('should allow access if headers matched', function() {
return preq.get({
uri: server.hostPort + '/header_match_filter',
headers: {
header_one: 'asdc',
header_two: 'test_two',
header_three: 'some_random_value'
}
})
.then(function(res) {
assert.deepEqual(res.status, 200);
assert.deepEqual(res.body.toString(), 'From Handler');
});
});
it('should restrict access if headers not matched', function() {
return preq.get({
uri: server.hostPort + '/header_match_filter',
headers: {
header_one: 'asdc123',
header_three: 'some_random_value'
}
})
.then(function() {
throw new Error('Error should be thrown');
}, function(e) {
assert.deepEqual(e.status, 403);
assert.deepEqual(e.body.detail, 'Test Message');
});
});
// Rate limits

@@ -53,0 +84,0 @@ it('Should allow low-volume access', function () {

@@ -211,3 +211,3 @@ 'use strict';

return preq.get({
uri: server.hostPort + '/service/gzip/get'
uri: server.hostPort + '/service/module/gzip'
})

@@ -222,3 +222,3 @@ .then(function(res) {

return preq.get({
uri: server.hostPort + '/service/gzip/get',
uri: server.hostPort + '/service/module/gzip',
headers: {

@@ -236,3 +236,12 @@ 'accept-encoding': 'identity'

it('Should get remote content with URI', function() {
return preq.get({
uri: server.hostPort + '/service/module/remote'
})
.then(function(res) {
assert.deepEqual(res.status, 200);
});
});
after(function() { return server.stop(); });
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc