npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@revealui/security

v0.6.0

Published

Security primitives — CSP/CORS/HSTS headers, RBAC + ABAC policy engine, encryption helpers, audit logging, GDPR compliance. Ships with RevealUI.

Readme


title: "@revealui/security" description: "Security infrastructure for RevealUI. Provides HTTP security headers, CORS management, RBAC/ABAC authorization, field-level encryption, audit logging, and GDPR compliance tooling." visibility: public status: verified audience: user

@revealui/security

Security infrastructure for RevealUI. Provides HTTP security headers, CORS management, RBAC/ABAC authorization, field-level encryption, audit logging, and GDPR compliance tooling.

When to Use This

  • You need security headers (CSP, HSTS, CORS) on HTTP responses
  • You're implementing role-based or attribute-based access control
  • You need audit logging for compliance (SOC2, HIPAA)
  • You need GDPR tooling: consent management, data export, breach reporting, anonymization
  • You need field-level encryption or key rotation
  • You need to sanitize untrusted input before rendering (terminal streams, shell args, SQL identifiers)

If you only need session auth (login/logout/password reset), use @revealui/auth instead.

Installation

pnpm add @revealui/security

Runtime dependencies: @revealui/contracts, @revealui/utils, parse5 (HTML sanitization), undici (SSRF/DNS checks in server subpath).

Subpath exports:

| Subpath | Contents | |---------|----------| | @revealui/security | Client-safe barrel — headers, CORS, authorization, encryption (Web Crypto), GDPR storage, alerting, request-IP, sanitization | | @revealui/security/server | Server-only modules using node: built-ins — auth, GDPR managers, audit logging, SSRF/DNS checks | | @revealui/security/sanitize | Minimal client-safe URL/HTML sanitize surface |

API Reference

Security Headers & CORS

| Export | Type | Purpose | |--------|------|---------| | SecurityHeaders | Class | Generate CSP, HSTS, Permissions-Policy, X-Frame-Options headers | | SecurityPresets | Object | Pre-built header configs (strict, moderate, development) | | CORSManager | Class | CORS origin/method/header management | | CORSPresets | Object | Pre-built CORS configs (restrictive, public API, development) | | createSecurityMiddleware | Function | Hono middleware applying all security headers | | setRateLimitHeaders | Function | Add X-RateLimit-* headers to responses |

Authorization (RBAC + ABAC)

| Export | Type | Purpose | |--------|------|---------| | AuthorizationSystem | Class | Combined RBAC + ABAC policy engine | | CommonRoles | Object | Pre-defined roles (admin, editor, viewer, superAdmin) | | PolicyBuilder | Class | Fluent API for building ABAC policies | | PermissionBuilder | Class | Fluent API for building RBAC permissions | | PermissionCache | Class | LRU cache for permission lookups | | canAccessResource | Function | Check if user can perform action on resource | | checkAttributeAccess | Function | Evaluate ABAC policy conditions | | createAuthorizationMiddleware | Function | Hono middleware for route-level authorization | | RequirePermission | Decorator | Enforce permission on class methods | | RequireRole | Decorator | Enforce role on class methods |

Encryption

| Export | Type | Purpose | |--------|------|---------| | EncryptionSystem | Class | AES-256 encryption with key management | | EnvelopeEncryption | Class | Envelope encryption (data key + master key) | | FieldEncryption | Class | Encrypt/decrypt individual database fields | | KeyRotationManager | Class | Scheduled key rotation with re-encryption | | DataMasking | Object helpers | Mask sensitive data for display (email, phone, SSN) | | TokenGenerator | Object helpers | Secure random token generation |

Security Alerting

| Export | Type | Purpose | |--------|------|---------| | SecurityAlertService | Class | Emit and route security alerts via pluggable handlers | | AuditAlertHandler | Class | Route alerts to the audit log | | LogAlertHandler | Class | Route alerts to the logger | | WebhookAlertHandler | Class | POST alerts to a webhook URL |

Audit Logging

Server-only (@revealui/security/server).

| Export | Type | Purpose | |--------|------|---------| | AuditSystem | Class | Structured audit event recording | | AuditTrail | Class | Query and filter audit history | | AuditReportGenerator | Class | Generate compliance reports from audit data | | createAuditMiddleware | Function | Hono middleware for automatic request auditing | | InMemoryAuditStorage | Class | In-memory storage for testing |

GDPR (server-only — import from @revealui/security/server) Compliance

| Export | Type | Purpose | |--------|------|---------| | ConsentManager | Class | Record and query user consent | | CookieConsentManager | Class | Browser cookie consent banner state | | DataDeletionSystem | Class | Right-to-erasure request processing | | DataExportSystem | Class | Right-to-portability data export | | DataAnonymization | Class | Anonymize user data while preserving analytics | | DataBreachManager | Class | Breach detection, notification, and reporting | | PrivacyPolicyManager | Class | Version and publish privacy policies | | InMemoryGDPRStorage | Class | In-memory GDPR storage for testing | | InMemoryBreachStorage | Class | In-memory breach storage for testing |

Input Sanitization

| Export | Type | Purpose | |--------|------|---------| | sanitizeTerminalLine | Function | Strip ANSI escape sequences; preserves SGR color codes, removes CSI/OSC/DCS and C0/C1 control chars | | sanitizeHtml | Function | Strip dangerous HTML (parse5-based); removes script/style/event-handler attributes | | sanitizeUrl | Function | Validate and sanitize URLs; blocks javascript:, vbscript:, data: schemes | | isSafeUrl | Function | Boolean check — true for http/https/relative/anchor URLs | | escapeShellArg | Function | Quote a value for safe use as a shell argument | | escapeSqlIdentifier | Function | Quote an identifier for safe use in SQL (double-quote, escape internal quotes) | | redactLogContext | Function | Redact sensitive keys in a log context object | | redactLogField | Function | Redact a single field value | | redactSecretsInString | Function | Scan a string and replace credential-shaped substrings with [REDACTED] | | isSensitiveLogKey | Function | Heuristic check whether a log key name looks like a secret |

Configuration & Utilities

| Export | Type | Purpose | |--------|------|---------| | configureSecurityLogger | Function | Set custom logger (defaults to console) | | configureClientIp | Function | Configure trusted-proxy settings for IP extraction | | getClientIp | Function | Extract client IP from a request (proxy-aware) |

Design Principles

  • Hermetic: Security boundaries are sealed - auth checks happen at middleware, never inside business logic
  • Sovereign: All security infrastructure runs in your deployment, no external auth service required
  • Justifiable: Every security header and policy has a documented reason (CSP prevents XSS, HSTS forces HTTPS, etc.)

Related Packages

  • @revealui/auth - Session-based authentication (login, password reset, OAuth)
  • @revealui/core - Applies security middleware to CMS routes
  • @revealui/contracts - Shared types for roles, permissions, consent records