
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
@jnode/server-ratelimit
Advanced tools
@jnode/server-ratelimitOfficial rate limit package for JNS.
npm i @jnode/server-ratelimit
const { createServer, routerConstructors: r, handlerConstructors: h } = require('@jnode/server');
const { routerConstructors: rr } = require('@jnode/server-ratelimit');
const server = createServer(
// apply rate limit: 5 requests per 5 seconds
rr.RateLimit(
// pass: what to do if the request is within limit
h.Text('Welcome! You are not rate-limited.'),
// fail: what to do if the request exceeds limit (default is 429)
h.Text('Too many requests, please try again later.', { statusCode: 429 }),
// limiter configuration
'tb: 5, 5s'
)
);
server.listen(8080);
const server = createServer(
rr.RateLimit(
h.Text('API accessed.'),
429,
// Configuration: 10 reqs / 1 min, GC every 5 mins,
// auto GC when > 2000 users, force GC every 2 hours
'tb: 10, 1m, 5m, 2000, 2h',
// identify by IP address specifically
'address',
{ disableRetryHeader: false }
)
);
server.listen(8080);
@jnode/server-ratelimit provides a router that acts as a gatekeeper.
When a request arrives:
by parameter, usually by IP address).pass router/handler.fail router/handler and optionally sets the Retry-After header.RateLimit(pass[, fail, limiter, by, options])pass router | handler-extended The router or handler to use if the rate limit has not been reached.fail router | handler-extended The router or handler to use if the rate limit is exceeded. Default: 429.limiter <string> | <Function>
type: args. Currently supported type is tb (Token Bucket).(identity) => true | number. Returns true to pass, or a number representing seconds until retry to fail.'tb: 5, 5s'.by <string> | <Function> How to identify the client.
'auto': Uses ctx.identity.id if available, otherwise ctx.identity.address.'address': Uses ctx.identity.address.(env, ctx) => identityString.'auto'.options <Object>
disableRetryHeader <boolean> If true, the Retry-After header will not be added to the response on failure. Default: false.tb) string formatThe limiter string for tb follows this comma-separated argument structure:
'tb: tokens, resetTime, gcTime, autoGC, forceGCTime, gcChunkSize'
tokens: Number of requests allowed per period.resetTime: Time duration before tokens refill (e.g., '5s', '1m', '1h').gcTime: How often to run garbage collection for inactive identities. Default: '10m'.autoGC: Max number of tracked identities before triggering GC. Default: 1000.forceGCTime: Maximum time to wait before forcing GC regardless of autoGC. Default: '1h'.gcChunkSize: Number of records to process per GC tick (to prevent blocking the event loop). Default: 500.Time units supported: ms, s, m, h, d. If no unit is provided, it defaults to seconds.
identifyFunctionsA map of built-in identification strategies.
auto: (env, ctx) => ctx.identity.id ?? ctx.identity.addressaddress: (env, ctx) => ctx.identity.addresslimitersA map of available limiter classes.
tb: TokenBucketLimiter class.RateLimitRouterThe class used to create the rate limit router.
new RateLimitRouter(pass[, fail, limiter, by, options])Same arguments as routerConstructors.RateLimit.
rateLimitRouter.route(env, ctx)Performs the rate limit check and returns either the pass or fail result.
FAQs
Official rate limit for JNS.
We found that @jnode/server-ratelimit demonstrated a healthy version release cadence and project activity because the last version was released less than 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.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.