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

solr-proxy

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

solr-proxy - npm Package Compare versions

Comparing version 7.0.0 to 8.0.0

6

bin/solr-proxy.js

@@ -7,2 +7,6 @@ #!/usr/bin/env node

cli.argv(argv, console.log, SolrProxy)
async function run () {
await cli.argv(argv, console.log, SolrProxy)
}
run()

74

index.js

@@ -1,3 +0,2 @@

const httpProxy = require('http-proxy')
const extend = require('xtend')
const fastify = require('fastify')

@@ -9,2 +8,9 @@ // To enable verbose logging, set environment variable:

const deny = function (req, res) {
debug('DENIED: ' + req.method + ' ' + req.url)
// res.writeHead(403, 'Forbidden')
// res.write('solrProxy: access denied\n')
res.code(403).send('Forbidden')
}
/*

@@ -16,13 +22,9 @@ * Returns true if the request satisfies the following conditions:

*/
const validateRequest = function (request, options) {
const parsedUrl = new URL(request.url, 'https://www.example.com/')
const validateRequest = async function (options, req, res) {
const parsedUrl = new URL(req.url, 'https://www.example.com/')
const path = parsedUrl.pathname
const queryParams = Array.from(parsedUrl.searchParams)
if (options.validHttpMethods.indexOf(request.method) === -1) {
return false
}
if (options.validPaths.indexOf(path) === -1) {
return false
return deny(req, res)
}

@@ -50,5 +52,4 @@

})) {
return false
return deny(req, res)
}
return true

@@ -62,6 +63,3 @@ }

invalidParams: ['qt', 'stream'],
backend: {
host: 'localhost',
port: 8983
},
upstream: 'http://localhost:8983',
maxRows: 200,

@@ -73,30 +71,22 @@ maxStart: 1000

debug('Creating server with options: %j', options)
const proxy = httpProxy.createProxyServer({ target: options.backend })
proxy.on('error', function (err, req, res) {
res.writeHead(502, { 'Content-Type': 'text/plain' })
res.end('Proxy error: ' + err)
})
let createServer
let server
if (options.ssl) {
const https = require('https')
createServer = (callback) => https.createServer(options.ssl, callback)
server = fastify({ https: options.ssl })
} else {
const http = require('http')
createServer = http.createServer
server = fastify()
}
// adapted from https://git.io/k5dCxQ
const server = createServer(function (request, response) {
if (validateRequest(request, options)) {
debug('ALLOWED: ' + request.method + ' ' + request.url)
proxy.web(request, response)
} else {
debug('DENIED: ' + request.method + ' ' + request.url)
response.writeHead(403, 'Illegal request')
response.write('solrProxy: access denied\n')
response.end()
}
server.register(require('fastify-http-proxy'), {
upstream: options.upstream,
httpMethods: options.validHttpMethods,
preHandler: validateRequest.bind(null, options)
})
server.setErrorHandler(function (err, req, res) {
debug('ERROR: ' + err)
// Send error response
res.status(502).send('Bad gateway')
})
return server

@@ -106,6 +96,6 @@ }

const SolrProxy = {
start: function (port, options) {
options = options || {}
options.backend = extend(defaultOptions.backend, options.backend)
options = extend(defaultOptions, options)
start: async function (port, options = {}) {
for (const option in defaultOptions) {
options[option] = options[option] || defaultOptions[option]
}

@@ -115,3 +105,3 @@ port = port || options.listenPort

const server = createServer(options)
server.listen(port)
await server.listen(port)
return server

@@ -118,0 +108,0 @@ }

const createProxyOptions = function (argv) {
const proxyOptions = {
backend: {}
}
const proxyOptions = {}
if (argv.backendPort) {
proxyOptions.backend.port = argv.backendPort
if (argv.upstream) {
proxyOptions.upstream = argv.upstream
}
if (argv.backendHost) {
proxyOptions.backend.host = argv.backendHost
}
if (argv.validMethods) {

@@ -37,20 +31,21 @@ proxyOptions.validHttpMethods = argv.validMethods.split(',')

module.exports = function (argv, stdout, SolrProxy) {
module.exports = async function (argv, stdout, SolrProxy) {
const usageMessage = 'Usage: solr-proxy [options]\n' +
'\n' +
'Options:\n' +
' --port Listen on this port [default: 8008]\n' +
' --backendPort Solr backend port [default: 8983]\n' +
' --backendHost Solr backend host [default: "localhost"]\n' +
' --validPaths Allowed paths (comma delimited) [default: "/solr/select"]\n' +
' --invalidParams Blocked parameters (comma [default: "qt,stream"]\n' +
' delimited)\n' +
' --validMethods Allowed HTTP methods (comma [default: "GET"]\n' +
' delimited)\n' +
' --maxRows Maximum rows permitted in a request [default: 200]\n' +
' --maxStart Maximum start offset permitted in a [default: 1000]\n' +
' request\n' +
' --quiet, -q Do not write messages to STDOUT\n' +
' --version, -v Show version\n' +
' --help, -h Show this message'
'Options:\n' +
'--port Listen on this port [default: 8008]\n' +
'--upstream Solr backend [default: "http://localhost:8983"]\n' +
'--validPaths Allowed paths (comma [default: "/solr/select"]\n' +
' delimited)\n' +
'--invalidParams Blocked parameters (comma [default: "qt,stream"]\n' +
' delimited)\n' +
'--validMethods Allowed HTTP methods (comma [default: "GET"]\n' +
' delimited)\n' +
'--maxRows Maximum rows permitted in a [default: 200]\n' +
' request\n' +
'--maxStart Maximum start offset [default: 1000]\n' +
' permitted in a request\n' +
'--quiet, -q Do not write messages to STDOUT\n' +
'--version, -v Show version\n' +
'--help, -h Show this message'

@@ -75,4 +70,4 @@ if (argv.help || argv.h) {

SolrProxy.start(argv.port, proxyOptions)
await SolrProxy.start(argv.port, proxyOptions)
stdout('solr-proxy is running...')
}

@@ -10,3 +10,3 @@ {

],
"version": "7.0.0",
"version": "8.0.0",
"author": "Rich Trott <rtrott@gmail.com>",

@@ -33,5 +33,5 @@ "bugs": {

"dependencies": {
"http-proxy": "^1.18.1",
"minimist": "^1.2.0",
"xtend": "^4.0.2"
"fastify": "^3.27.1",
"fastify-http-proxy": "^6.2.2",
"minimist": "^1.2.0"
},

@@ -38,0 +38,0 @@ "devDependencies": {

@@ -38,16 +38,17 @@ solr-proxy

Options:
--port Listen on this port [default: 8008]
--backendPort Solr backend port [default: 8983]
--backendHost Solr backend host [default: "localhost"]
--validPaths Allowed paths (comma delimited) [default: "/solr/select"]
--invalidParams Blocked parameters (comma [default: "qt,stream"]
delimited)
--validMethods Allowed HTTP methods (comma [default: "GET"]
delimited)
--maxRows Maximum rows permitted in a request [default: 200]
--maxStart Maximum start offset permitted in a [default: 1000]
request
--quiet, -q Do not write messages to STDOUT
--version, -v Show version
--help, -h Show this message
--port Listen on this port [default: 8008]
--upstream Solr backend [default: "http://localhost:8983"]
--validPaths Allowed paths (comma [default: "/solr/select"]
delimited)
--invalidParams Blocked parameters (comma [default: "qt,stream"]
delimited)
--validMethods Allowed HTTP methods (comma [default: "GET"]
delimited)
--maxRows Maximum rows permitted in a [default: 200]
request
--maxStart Maximum start offset [default: 1000]
permitted in a request
--quiet, -q Do not write messages to STDOUT
--version, -v Show version
--help, -h Show this message
```

@@ -58,4 +59,4 @@

```js
var SolrProxy = require('solr-proxy');
SolrProxy.start();
const SolrProxy = require('solr-proxy')
await SolrProxy.start()
```

@@ -72,11 +73,8 @@

```js
var defaultOptions = {
const defaultOptions = {
validHttpMethods: ['GET'], // all other HTTP methods will be disallowed
validPaths: ['/solr/select'], // all other paths will be denied
invalidParams: ['qt', 'stream'], // blocks requests with params qt or stream.* (all other params are allowed)
backend: { // proxy to solr at this location
host: 'localhost',
port: 8080
}
};
upstream: 'http://localhost:8008' // proxy to solr at this location
}
```

@@ -88,3 +86,3 @@

```js
var options = {
const options = {
ssl: {

@@ -94,9 +92,6 @@ key: fs.readFileSync('key.pem'),

}
};
var proxy = SolrProxy.start(null, options);
}
const proxy = await SolrProxy.start(null, options);
```
To enable verbose logging, set environment variable `DEBUG` to include
`solr-proxy`.
Default Rules

@@ -103,0 +98,0 @@ -------------

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