@ui18n/angular
Version:
🅰️ Modern Angular internationalization with standalone components, signals, and dependency injection support for Angular 15+
105 lines • 2.6 kB
TypeScript
/**
* 安全相关功能
* 提供XSS防护和输入验证
*/
/**
* 标记为原始HTML(不进行转义)
*/
export declare class RawHTML {
readonly value: string;
constructor(value: string);
toString(): string;
}
/**
* 创建原始HTML标记(安全绕过通道)
* @param html - 原始HTML字符串
* @returns RawHTML实例
* @example
* // 需要输出原始HTML时使用
* const content = raw('<strong>Bold Text</strong>');
*/
export declare function raw(html: string): RawHTML;
/**
* 检查是否为原始HTML
*/
export declare function isRawHTML(value: unknown): value is RawHTML;
/**
* 转义HTML字符串,防止XSS攻击
* @param str 需要转义的字符串
* @returns 转义后的安全字符串
*/
export declare function escapeHtml(str: string | unknown): string;
/**
* 验证并清理用户输入
* @param input 用户输入
* @param options 验证选项
* @returns 清理后的输入
*/
export declare function sanitizeInput(input: string, options?: {
maxLength?: number;
allowedTags?: string[];
stripScripts?: boolean;
}): string;
/**
* 插值参数的安全处理
* @param template 模板字符串
* @param params 插值参数
* @param escapeParams 是否转义参数(默认true)
* @returns 处理后的字符串
*/
export declare function interpolateSafely(template: string, params?: Record<string, any>, escapeParams?: boolean): string;
/**
* 检测潜在的XSS攻击向量
* @param input 输入字符串
* @returns 是否包含危险内容
*/
export declare function detectXSS(input: string): boolean;
/**
* 安全配置接口
*/
export interface SecurityConfig {
/**
* 是否默认转义HTML(推荐true)
*/
escapeByDefault?: boolean;
/**
* 最大输入长度
*/
maxInputLength?: number;
/**
* 是否检测XSS
*/
detectXSS?: boolean;
/**
* 是否记录安全事件
*/
logSecurityEvents?: boolean;
/**
* 自定义转义函数
*/
customEscapeFn?: (str: string) => string;
}
/**
* 默认安全配置
*/
export declare const DEFAULT_SECURITY_CONFIG: SecurityConfig;
/**
* 安全管理器类
*/
export declare class SecurityManager {
private config;
constructor(config?: SecurityConfig);
/**
* 处理不受信任的输入
*/
processUntrustedInput(input: string | unknown): string;
/**
* 更新配置
*/
updateConfig(config: Partial<SecurityConfig>): void;
/**
* 获取当前配置
*/
getConfig(): SecurityConfig;
}
//# sourceMappingURL=security.d.ts.map