🚨 Active Supply Chain Attack:node-ipc Package Compromised.Learn More
Socket
Book a DemoSign in
Socket

@aegis-sdk/fastify

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aegis-sdk/fastify

Fastify plugin adapter for Aegis prompt injection defense

latest
Source
npmnpm
Version
0.5.0
Version published
Weekly downloads
12
-7.69%
Maintainers
1
Weekly downloads
 
Created
Source

@aegis-sdk/fastify

Fastify plugin for scanning LLM chat messages against prompt injection attacks.

Part of the Aegis.js prompt injection defense toolkit.

Installation

npm install @aegis-sdk/fastify @aegis-sdk/core

Quick Start

import Fastify from 'fastify';
import { aegisPlugin } from '@aegis-sdk/fastify';

const app = Fastify();

app.register(aegisPlugin, {
  aegis: { policy: 'strict' },
  routes: ['/api/chat'],
});

app.post('/api/chat', async (request, reply) => {
  const { messages, instance } = request.aegis; // scanned messages
  // pass messages to your LLM
  return { reply: '...' };
});

app.listen({ port: 3000 });

API

aegisPlugin

Fastify plugin that registers a preHandler hook. The hook reads messages from the request body, runs them through aegis.guardInput(), and attaches the safe messages to request.aegis. Returns 403 with violation details if input is blocked.

Register it with app.register(aegisPlugin, options):

OptionTypeDefaultDescription
aegisAegisConfig | Aegis{}Aegis configuration or pre-constructed instance
routes(string | RegExp)[]--Routes to protect. If omitted, all POST requests are scanned
methodsstring[]["POST"]HTTP methods to scan
messagesPropertystring"messages"Property on the request body to read messages from
scanStrategyScanStrategy"last-user"Which messages to scan
onBlocked(request, reply, error) => unknown--Custom error handler. Return truthy to take over the response

Access scan results in your handler via request.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.

guardMessages(aegis, messages, options?)

Scans messages directly without using the plugin. Throws AegisInputBlocked if input is blocked.

Re-exports

Aegis, AegisInputBlocked, AegisSessionQuarantined, AegisSessionTerminated, and all core types are re-exported for convenience.

Learn More

License

MIT

FAQs

Package last updated on 24 Feb 2026

Did you know?

Socket

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.

Install

Related posts