Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
middleman-proxy
Advanced tools
HTTP proxy with content caching.
$ npm install --save middleman-proxy
const Middleman = require('middleman-proxy')
const proxy = new Middleman({
target: 'http://some.api.com',
maxAge: 3600000,
maxSize: '1MB'
})
.createKey((req, url) => `${req.method}:${req.session.id}:${url.path}`)
.listen(3000, () => {
console.log('Proxing "http://some.api.com" on port 3000')
})
By default, Middleman's cache is a Least-Recently-Used managed, in-memory cache, but it can just as easily work with any persistent store.
The Cache really manages an index of "keys" that are associated with "entries" in the store. The keys also contain the size in bytes of the associated entry, which allows the LRU work properly. Basically, when a key is evicted, a call is made to the store to deleted that entry. This allows the LRU to work even with out-of-memory stores. See Implementing a Store for more details.
The "store" is really just an interface, and a simple one at that.
Promise
, resolves the cache value if it exists, and null
if not.Promise
, resolves value
Promise
, resolves true
More than that, it's perfectly fine to resolve JSON strings; Middleman will automatically take care of parsing.
Recently, I have been working on a project that depended upon a very slow api; up to 40+ seconds in some instances. Due to circumstances, a standalone proxy was not an option. While making a hand-rolled solution, I thought it would be useful to have an in-application caching proxy solution for small apps. So I made Middleman!
const Middleman = require('middleman-proxy')
const app = require('express')()
const proxy = new Middleman({
target: 'http://some.api.com'
})
app.use(proxy.handler())
// OR
app.use((req, res) => {
// do some stuff ...
proxy.http(req, res)
});
app.get('/nameSpace', (req, res) => {
proxy.http(req, res, {
stripPrefix: '/nameSpace',
basePath: '/someBasePath'
})
// GET /nameSpace/path?foo=bar#baz
// => (Proxy) GET http://some.api.com/someBasePath/path?foo=bar#baz
})
// OR
app.get('/nameSpace', proxy.handler({
stripPrefix: '/nameSpace',
basePath: '/someBasePath'
}))
const Middleman = require('middleman-proxy')
const proxy = new Middleman({
target: 'http://some.api.com',
setHeaders: {
'X-API-Key': `${API_KEY}`,
'Authorization': `Bearer ${getAccessToken()}`
}
})
.listen(3000)
const Middleman = require('middleman-proxy')
const proxy = new Middleman({
target: 'http://some.api.com',
ignoreHeaders: [
'X-Some-Header'
]
})
const Middleman = require('middleman-proxy')
const proxy = new Middleman({
target: 'http://some.api.com'
})
.on('request', (req, res) => {
// For every request
res.setHeader('X-Always', 'true')
})
.on('proxy request', (req, res) => {
// For requests being proxied
res.setHeader('X-Proxied', 'true')
})
.on('cache request', (req, res) => {
// For requests with cached responses
res.setHeader('X-Cached', 'true')
})
{}
[]
'any'
Infinity
Infinity
. Note: If it is a string, it is parsed by the bytes
library, hence
values like '1KB'
or '13MB'
are perfectly acceptable.true
MemoryStore
. See
Implementing a Store for more details.true
.res
(instance of http.IncomingMessage)
which is a response from the proxied host, and returns a boolean; true
and the response is
not cached, false
and the response is cached. Default () => true
.req
(http.IncomingMessage)
and url
(Object) and returns a key
for the cache entry. Default
(req, url) => req.method + ':' + url.path
''
''
Handles a "request" event.const proxy = new Middleman({target: 'http://some.api.com'})
// ...
proxy.http(req, res, {
stripPrefix: '/namespace',
basePath: '/someBasePath'
})
// GET /namespace/path?foo=bar#baz => http://some.api.com/someBasePath/path?foo=bar#baz
Returns Middleman#http() bound with the instances context. See Middleman#http.
Populates the instances server
property with an instance of http.Server
, and
binds to the port
.
instance.listen(3000, () => {
console.log('Middleman instance is now serving on port 3000')
})
createKey
instance
.createKey((req, url) => {
return `${req.method}:${req.session.id}:${url.path}`
})
.listen(3000)
bypass
instance
.bypass((res) => {
if (res.statusCode < 300) {
return false // this response is cached
} else {
return true // not caching this one
}
})
.listen(3000)
httpError
instance
.httpError((req, res) => {
res.statusCode = 500
res.end('Whoops! Something blew up...')
})
.listen(3000)
MIT
FAQs
HTTP Proxy with content caching.
The npm package middleman-proxy receives a total of 11 weekly downloads. As such, middleman-proxy popularity was classified as not popular.
We found that middleman-proxy demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.