UNPKG

ntfy-mcp-server

Version:

An MCP (Model Context Protocol) server designed to interact with the ntfy push notification service. It enables LLMs and AI agents to send notifications to your devices with extensive customization options.

225 lines (224 loc) 8.13 kB
import sanitizeHtml from 'sanitize-html'; /** * Options for path sanitization */ export interface PathSanitizeOptions { /** Restrict paths to a specific root directory */ rootDir?: string; /** Normalize Windows-style paths to POSIX-style */ toPosix?: boolean; /** Allow absolute paths (if false, converts to relative paths) */ allowAbsolute?: boolean; } /** * Context-specific input sanitization options */ export interface SanitizeStringOptions { /** Handle content differently based on context */ context?: 'text' | 'html' | 'attribute' | 'url' | 'javascript'; /** Custom allowed tags when using html context */ allowedTags?: string[]; /** Custom allowed attributes when using html context */ allowedAttributes?: Record<string, string[]>; } /** * Configuration for HTML sanitization */ export interface HtmlSanitizeConfig { /** Allowed HTML tags */ allowedTags?: string[]; /** Allowed HTML attributes (global or per-tag) */ allowedAttributes?: sanitizeHtml.IOptions['allowedAttributes']; /** Allow preserving comments - uses allowedTags internally */ preserveComments?: boolean; /** Custom URL sanitizer */ transformTags?: sanitizeHtml.IOptions['transformTags']; } /** * Sanitization class for handling various input sanitization tasks */ export declare class Sanitization { private static instance; /** Default list of sensitive fields for sanitizing logs */ private sensitiveFields; /** Default sanitize-html configuration */ private defaultHtmlSanitizeConfig; /** * Private constructor to enforce singleton pattern */ private constructor(); /** * Get the singleton Sanitization instance * @returns Sanitization instance */ static getInstance(): Sanitization; /** * Set sensitive fields for log sanitization * @param fields Array of field names to consider sensitive */ setSensitiveFields(fields: string[]): void; /** * Get the current list of sensitive fields * @returns Array of sensitive field names */ getSensitiveFields(): string[]; /** * Sanitize HTML content using sanitize-html library * @param input HTML string to sanitize * @param config Optional custom sanitization config * @returns Sanitized HTML */ sanitizeHtml(input: string, config?: HtmlSanitizeConfig): string; /** * Sanitize string input based on context * @param input String to sanitize * @param options Sanitization options * @returns Sanitized string */ sanitizeString(input: string, options?: SanitizeStringOptions): string; /** * Sanitize URL with robust validation and sanitization * @param input URL to sanitize * @param allowedProtocols Allowed URL protocols * @returns Sanitized URL */ sanitizeUrl(input: string, allowedProtocols?: string[]): string; /** * Sanitize file paths to prevent path traversal attacks * @param input Path to sanitize * @param options Options for path sanitization * @returns Sanitized and normalized path */ sanitizePath(input: string, options?: PathSanitizeOptions): string; /** * Sanitize a JSON string * @param input JSON string to sanitize * @param maxSize Maximum allowed size in bytes * @returns Parsed and sanitized object */ sanitizeJson<T = unknown>(input: string, maxSize?: number): T; /** * Ensure input is within a numeric range * @param input Number to validate * @param min Minimum allowed value * @param max Maximum allowed value * @returns Sanitized number within range */ sanitizeNumber(input: number | string, min?: number, max?: number): number; /** * Sanitize input for logging to protect sensitive information * @param input Input to sanitize * @returns Sanitized input safe for logging */ sanitizeForLogging(input: unknown): unknown; /** * Private helper to convert attribute format from record to sanitize-html format */ private convertAttributesFormat; /** * Recursively redact sensitive fields in an object */ private redactSensitiveFields; } export declare const sanitization: Sanitization; export declare const sanitizeInput: { /** * Remove potentially dangerous characters from strings based on context * @param input String to sanitize * @param options Sanitization options for context-specific handling * @returns Sanitized string */ string: (input: string, options?: SanitizeStringOptions) => string; /** * Sanitize HTML to prevent XSS * @param input HTML string to sanitize * @param config Optional custom sanitization config * @returns Sanitized HTML */ html: (input: string, config?: HtmlSanitizeConfig) => string; /** * Sanitize URLs * @param input URL to sanitize * @param allowedProtocols Allowed URL protocols * @returns Sanitized URL */ url: (input: string, allowedProtocols?: string[]) => string; /** * Sanitize file paths to prevent path traversal attacks * @param input Path to sanitize * @param options Options for path sanitization * @returns Sanitized and normalized path */ path: (input: string, options?: PathSanitizeOptions) => string; /** * Sanitize a JSON string * @param input JSON string to sanitize * @param maxSize Maximum allowed size in bytes * @returns Parsed and sanitized object */ json: <T = unknown>(input: string, maxSize?: number) => T; /** * Ensure input is within a numeric range * @param input Number to validate * @param min Minimum allowed value * @param max Maximum allowed value * @returns Sanitized number within range */ number: (input: number | string, min?: number, max?: number) => number; }; /** * Sanitize input for logging to protect sensitive information * @param input Input to sanitize * @returns Sanitized input safe for logging */ export declare const sanitizeInputForLogging: (input: unknown) => unknown; declare const _default: { sanitization: Sanitization; sanitizeInput: { /** * Remove potentially dangerous characters from strings based on context * @param input String to sanitize * @param options Sanitization options for context-specific handling * @returns Sanitized string */ string: (input: string, options?: SanitizeStringOptions) => string; /** * Sanitize HTML to prevent XSS * @param input HTML string to sanitize * @param config Optional custom sanitization config * @returns Sanitized HTML */ html: (input: string, config?: HtmlSanitizeConfig) => string; /** * Sanitize URLs * @param input URL to sanitize * @param allowedProtocols Allowed URL protocols * @returns Sanitized URL */ url: (input: string, allowedProtocols?: string[]) => string; /** * Sanitize file paths to prevent path traversal attacks * @param input Path to sanitize * @param options Options for path sanitization * @returns Sanitized and normalized path */ path: (input: string, options?: PathSanitizeOptions) => string; /** * Sanitize a JSON string * @param input JSON string to sanitize * @param maxSize Maximum allowed size in bytes * @returns Parsed and sanitized object */ json: <T = unknown>(input: string, maxSize?: number) => T; /** * Ensure input is within a numeric range * @param input Number to validate * @param min Minimum allowed value * @param max Maximum allowed value * @returns Sanitized number within range */ number: (input: number | string, min?: number, max?: number) => number; }; sanitizeInputForLogging: (input: unknown) => unknown; }; export default _default;