@juspay/neurolink
Version:
Universal AI Development Platform with working MCP integration, multi-provider support, voice (TTS/STT/realtime), and professional CLI. 58+ external MCP servers discoverable, multimodal file processing, RAG pipelines. Build, test, and deploy AI applicatio
159 lines (158 loc) • 5.15 kB
TypeScript
/**
* XML Processing Utility
*
* Handles downloading, validating, and processing XML files with security.
*
* Security Notes:
* ---------------
* XML parsing can be vulnerable to XML External Entity (XXE) attacks:
*
* 1. **XXE Attacks**: DOCTYPE and ENTITY declarations can be exploited to:
* - Read local files on the server
* - Perform Server-Side Request Forgery (SSRF)
* - Cause Denial of Service via entity expansion
*
* 2. **Mitigation**: We reject XML files containing DOCTYPE or ENTITY declarations
* and disable entity processing in the parser.
*
* References:
* - https://owasp.org/www-community/vulnerabilities/XML_External_Entity_(XXE)_Processing
* - https://cwe.mitre.org/data/definitions/611.html (XXE)
*
* @module processors/data/XmlProcessor
*
* @example
* ```typescript
* import { xmlProcessor, isXmlFile, processXml } from "./XmlProcessor.js";
*
* // Check if file is XML
* if (isXmlFile("application/xml", "data.xml")) {
* // Process the file
* const result = await processXml(fileInfo);
* if (result.success && result.data) {
* console.log("Root element:", result.data.rootElement);
* console.log("Parsed:", result.data.parsed);
* }
* }
* ```
*/
import { BaseFileProcessor } from "../base/BaseFileProcessor.js";
import type { FileInfo, ProcessorFileProcessingResult, ProcessorOperationResult, ProcessOptions, ProcessedXml } from "../../types/index.js";
/**
* XML file processor.
* Extends BaseFileProcessor with XML-specific parsing and validation.
*
* Features:
* - XXE protection (rejects DOCTYPE and ENTITY declarations)
* - Parses XML to JavaScript objects
* - Extracts root element name
*
* @example
* ```typescript
* const processor = new XmlProcessor();
*
* const result = await processor.processFile({
* id: "file-123",
* name: "data.xml",
* mimetype: "application/xml",
* size: 1024,
* buffer: xmlBuffer,
* });
*
* if (result.success && result.data?.valid) {
* console.log("Root element:", result.data.rootElement);
* }
* ```
*/
export declare class XmlProcessor extends BaseFileProcessor<ProcessedXml> {
constructor();
/**
* Extract the root element name from XML content.
*
* @param content - XML content string
* @returns Root element name or undefined if not found
*/
private extractRootElement;
/**
* Check if XML content contains XXE attack vectors.
*
* @param content - XML content string
* @returns Object with detection results
*/
private checkXxeVectors;
/**
* Parse XML content to JavaScript object securely.
*
* @param content - XML content string
* @returns Parsed XML content
*/
private parseXmlSecurely;
/**
* Validate downloaded XML is parseable and safe with structured error result.
* Includes XXE protection by rejecting XML with DOCTYPE or ENTITY declarations.
* Returns user-friendly error messages with actionable suggestions.
*
* @param buffer - Downloaded file content
* @param fileInfo - Original file information
* @returns Success result or error result
*/
protected validateDownloadedFileWithResult(buffer: Buffer, fileInfo: FileInfo): Promise<ProcessorOperationResult<void>>;
/**
* Build processed XML result with parsed content.
*
* @param buffer - Downloaded file content
* @param fileInfo - Original file information
* @returns Processed XML result
*/
protected buildProcessedResult(buffer: Buffer, fileInfo: FileInfo): ProcessedXml;
}
/** Singleton XML processor instance */
export declare const xmlProcessor: XmlProcessor;
/**
* Check if a file is an XML file based on MIME type or extension.
*
* @param mimetype - MIME type of the file
* @param filename - Filename (for extension-based detection)
* @returns true if the file is an XML file
*
* @example
* ```typescript
* if (isXmlFile("application/xml", "data.xml")) {
* // Process as XML
* }
* ```
*/
export declare function isXmlFile(mimetype: string, filename: string): boolean;
/**
* Validate XML file size against configured limit.
*
* @param sizeBytes - File size in bytes
* @returns true if size is within the limit
*/
export declare function validateXmlSize(sizeBytes: number): boolean;
/**
* Process a single XML file with XXE protection.
*
* @param fileInfo - File information (with URL or buffer)
* @param options - Optional processing options (auth headers, timeout, retry config)
* @returns Processing result with parsed XML or error
*
* @example
* ```typescript
* const result = await processXml({
* id: "file-123",
* name: "data.xml",
* mimetype: "application/xml",
* size: 2048,
* url: "https://example.com/data.xml",
* }, {
* authHeaders: { "Authorization": "Bearer token" },
* });
*
* if (result.success && result.data) {
* console.log("Root:", result.data.rootElement);
* console.log("Parsed:", result.data.parsed);
* }
* ```
*/
export declare function processXml(fileInfo: FileInfo, options?: ProcessOptions): Promise<ProcessorFileProcessingResult<ProcessedXml>>;