
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
@nxcd/auth-api-key
Advanced tools
Authentication Middleware for Expresso by api-key
Install:
$ npm i @nxcd/auth-api-key
Import and use:
const { app } = require('@expresso/app')
const server = require('@expresso/server')
const { factory: errors } = require('@expresso/errors')
// Import auth-api-key module
const { factory: apiKeyFactory, scopes } = require('auth-api-key')
const appFactory = app((app, config, environment) => {
const { mongodbConnection, redisConnection } = await database.factory(config.database)
const { apiKey } = apiKeyFactory(mongodbConnection, redisConnection, config.apiKey)
app.get('/', apiKey, scopes('namespace:your-scope-a'), routeHandler)
})
const options = {
name: 'myApp',
apiKey: {
scopesField: 'permissions',
mongodbRepository: {
collectionName: 'serviceAccounts',
fields: {
key: 'state.userId',
secret: 'state.token',
enabledCriteria: { 'state.deletedAt': null }
},
projection: 'state'
},
redisRepository: {
context: 'sessions',
ttl: 15 // seconds
}
}
}
server.start(appFactory, options)
The mongodb connection and redis connection is required. The user and their permissions will be fetched from redis and if not found they will be fetched from mongodb and then sent to redis.
const { MongoClient } = require('mongodb')
const defaults = {
poolSize: 10,
useNewUrlParser: true
}
const connect = async ({ url, dbname, options = { } }) => {
const client = await MongoClient.connect(url, { ...defaults, ...options })
return client.db(dbname)
}
module.exports = { connect }
const redis = require('redis')
const connect = ({ uri }) => {
const client = redis.createClient({ url: uri })
return client
}
module.exports = { connect }
The auth api-key middleware takes option object as configuration. This object is as follows with default values:
const apiKeyConfig = {
scopesField: 'permissions',
mongodbRepository: {
collectionName: 'serviceAccounts',
fields: {
key: 'state.userId',
secret: 'state.token',
enabledCriteria: { 'state.deletedAt': null }
},
projection: 'state'
},
redisRepository: {
context: 'sessions',
ttl: 15 // seconds
}
}
The scopesField
gets the field name that has the enabled scopes from user in database, by default is "permissions". This field will be obtained from projection result.
The mongodbRepository.enabledCriteria
receive an 'object' with a criteria to filter only fit users, for example excluding inactive users.
This middleware supports scopes. This means you can restrict your token to explicit permission levels using the scopes
in database entity:
{
"name": "John Doe",
"user": "johndoe",
"passwordHash": "28dffbf8c249c638465005663d605b46dcd581bdfc5fd",
"scopes": [ "namespace:your-scope-a", "namespace:your-scope-b" ]
}
The scope
can be either a string or an Array. But it'll only validate if your determined scope is equal to the string or if it is included in the array.
You can perform wildcard validation using the
*
keyword as long as your scope separator is.
, for instance,users.*
will match all the scopes within theusers
namespace, butusers:*
won't.
For more information see is-path-in-scope.
FAQs
A express middleware to authentication by api-key
We found that @nxcd/auth-api-key demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers 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
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.