
Security News
AI Has Taken Over Open Source
Vibe coding at scale is reshaping how packages are created, contributed, and selected across the software supply chain
@aegis-sdk/koa
Advanced tools
Koa middleware for scanning LLM chat messages against prompt injection attacks.
Part of the Aegis.js prompt injection defense toolkit.
npm install @aegis-sdk/koa @aegis-sdk/core
import Koa from 'koa';
import bodyParser from 'koa-bodyparser';
import { aegisMiddleware } from '@aegis-sdk/koa';
const app = new Koa();
app.use(bodyParser());
app.use(aegisMiddleware({ policy: 'strict' }));
app.use(async (ctx) => {
const { messages, instance } = ctx.state.aegis; // scanned messages
// pass messages to your LLM
ctx.body = { reply: '...' };
});
app.listen(3000);
aegisMiddleware(options?)Creates Koa middleware that reads ctx.request.body.messages, runs them through aegis.guardInput(), and attaches the safe messages to ctx.state.aegis. Returns 403 with violation details if input is blocked.
Requires a body parsing middleware (e.g., koa-bodyparser) to be applied first.
Accepts either an AegisConfig directly or an AegisMiddlewareOptions object:
| Option | Type | Default | Description |
|---|---|---|---|
aegis | AegisConfig | Aegis | {} | Aegis configuration or pre-constructed instance |
messagesProperty | string | "messages" | Property on ctx.request.body to read messages from |
scanStrategy | ScanStrategy | "last-user" | Which messages to scan |
onBlocked | (ctx, detections, error) => boolean | -- | Custom error handler. Return true to take over the response |
Access scan results in downstream middleware via ctx.state.aegis, which returns { messages, instance, auditLog }.
aegisStreamTransform(configOrInstance?)Returns a TransformStream<string, string> that monitors LLM output tokens for injection payloads, PII leaks, and canary token leaks.
app.use(async (ctx) => {
const transform = aegisStreamTransform(ctx.state.aegis.instance);
const monitoredStream = llmStream.pipeThrough(transform);
// pipe the monitored stream to the response
});
guardMessages(aegis, messages, options?)Scans messages directly without using the middleware. Throws AegisInputBlocked if input is blocked.
Aegis, AegisInputBlocked, AegisSessionQuarantined, AegisSessionTerminated, and all core types are re-exported for convenience.
MIT
FAQs
Koa middleware adapter for Aegis prompt injection defense
The npm package @aegis-sdk/koa receives a total of 0 weekly downloads. As such, @aegis-sdk/koa popularity was classified as not popular.
We found that @aegis-sdk/koa 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
Vibe coding at scale is reshaping how packages are created, contributed, and selected across the software supply chain

Security News
npm invalidated all granular access tokens that bypass 2FA after a fresh Mini Shai-Hulud wave compromised 323 npm packages. Staged publishing also entered public preview.

Research
/Security News
Compromised npm package art-template delivered a Coruna-like iOS Safari exploit framework through a watering-hole attack.