
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
@ashnazg/atst
Advanced tools
Ashnazg Tiny Server Template -- a koa2-based toolkit for RAD of versioned APIs
This is a koa wrapper I use to...
You can set port programmatically or through $PORT
const atst = require('@ashnazg/atst'); // ~/projects/ashnazg-npm/atst/atst.js
const service = atst({port: 1234});
The public instance of @koa/router is exposed at service.public, but for syntactic sugar, that router's get/post/delete/put methods are also available on service itself:
service.get('/status', async ctx => {
return {status: 'running'};
});
You still can just set ctx.body, or you can just return a jsonable object. (See '/status' above.)
The koa context is extended with ctx.fail and ctx.warn, which take errors in either of these formats:
You can also throw and that'll be converted to ctx.fail().
With or without a ctx.body, the response to client will always include {errors: [], warnings: []}. 4xx events are shown to the user; 5xx events are logged and only a unique event ID is in the response.
While warnings don't affect the HTTP main code/message, errors do; if there's only 4xx type errors, the highest code will also be used for the HTTP response.
errors:[] but the response is a 500.These three are translated to ctx.fail():
By default, it logs to stdout/err. You can divert access logs to a file:
const service = atst({
access_log_dest: '/var/log/myservice.log',
error_log_dest: '/var/log/myservice.errs'
});
Or to your own handler: const service = atst({ access_log_dest(evt) { // process access event }, error_log_dest(evt) { // process errors that are code >= 500 } });
For short-lived servers in a TDD context, you can also set it to just accumulate logs in memory:
const hits = [];
const errors = [];
const service = atst({
access_log_dest: hits
error_log_dest: errors
});
assert.deepEqual(await curlAtDevServer('/status'), {stuff});
assert(hits.length === 1, 'access event should have been recorded');
assert(errors.length === 0, 'there should be no errors');
To turn on local passport plugins and the protected route support, pass in a function that takes user/pass and returns a promise to a user record. If the user record includes uid:number, that'll be reflected in access logs.
local() can throw or return undefined to signal a rejection.
const service = atst({
auth: {
keys: [process.env.SECRET1, process.env.SECRET2],
session_length_days: 7,
async local(user, pass) {
return {uid: 1, roles: ['admin']};
}
}
});
atst.authed.get('/secret', async ctx => {
return {secret: 'data'};
});
set session_length_days in auth{} or it'll default to 7.
(For testing convenience, you can instead set session_length_ms.)
By default, atst uses a per-instance in-memory session cache.
Add three hooks to auth to redirect session management:
const sessions = {};
const service = atst({
auth: {
keys: [process.env.SECRET1, process.env.SECRET2],
session_length_days: 7
async local(user, pass) {
return {uid: 1, roles: ['admin']};
},
async setSession(key, profile) {
sessions[key] = profile;
},
async getSession(key) {
return sessions[key];
},
async deleteSession(key) {
delete sessions[key];
}
}
});
By default, atst only sets up public/authed routes.
You can create routing blocks with special permission rules by first defining the test functions at setup, and they can check user profile fields at request time:
const service = atst({
prefix: '/allendpoints',
auth: {
keys: [process.env.SECRET1, process.env.SECRET2],
async local(user, pass) {
return {uid: 1, roles: ['admin']};
},
roles: {
admin(profile) {
return profile.roles.indexOf('admin') !== -1;
}
}
}
});
atst.admin.get('/sensitive-stuff', async ctx => {
return {secret: 'data'};
});
# curl server/allendpoints/admin/sensitive-stuff
FAQs
Ashnazg Tiny Server Template -- a koa2-based toolkit for RAD of versioned APIs
We found that @ashnazg/atst 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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.