A plugin for Elysia.js that provides XSS (Cross-Site Scripting) protection by sanitizing request body data.
- đĄī¸ Automatic XSS protection for request body data
- đ Recursive sanitization of nested objects and arrays
- đ¯ Configurable scope options
- đĒļ Lightweight with minimal dependencies
- đ Built for Elysia.js and Bun
bun add elysia-xss
import { Elysia } from 'elysia'
import { elysiaXSS } from 'elysia-xss'
const app = new Elysia()
.use(elysiaXSS({}))
.get("/", () => "Hello World!")
.listen(3000)
The plugin accepts a configuration object with the following options:
{
as?: "global" | "scoped" | "local" // Default: "global"
}
import { Elysia } from 'elysia'
import { elysiaXSS } from 'elysia-xss'
const app = new Elysia()
.use(elysiaXSS({ as: "scoped" }))
.post("/submit", ({ body }) => {
// body is automatically sanitized
return { message: "Data received", data: body }
})
.listen(3000)
The plugin automatically sanitizes all string values in the request body, including nested objects and arrays. It uses the xss package under the hood for sanitization.
MIT
Contributions are welcome! Please feel free to submit a Pull Request.