SmythOS Studio: Open-Source Visual AI Agent Builder and deployable runtime stack from SmythOS. Start with an intuitive drag-and-drop workspace, extend with custom code, and deploy your agents anywhere — local, cloud, or edge — with full governance and control.
JavaScript a2aagentic-aiai-agentsdevtoolsmcp-clientn8n-alternativeno-codeopen-sourceorchestrationsmythosvisual-builder
Implement HTML escaping in debugger to prevent XSS vulnerabilities (#77)
Salman Ahamed6d88a01181be
diff --git a/packages/app/src/builder-ui/debugger.ts b/packages/app/src/builder-ui/debugger.tsindex 607fc410..28cf0433 100644--- a/packages/app/src/builder-ui/debugger.ts+++ b/packages/app/src/builder-ui/debugger.ts@@ -927,13 +927,28 @@ function getFormattedContent(content, compName?) {previewBtn = `<div class="text-center"><a href="#" class="w-[100px] px-3 py-1 text-xs font-medium text-center text-white bg-blue-700 rounded-md hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800 btn-file-preview" data-is-image-generator="${isImageGenerator}">${'Preview'}</a></div>`;}+ // SECURITY FIX: Escape HTML content to prevent XSS attacks+ // This ensures that HTML tags are displayed as plain text, never rendered+ const escapeHtml = (text: string): string => {+ if (typeof text !== 'string') return text;++ // Replace HTML special characters with their entity equivalents+ return text+ .replace(/&/g, '&') // Must be first to avoid double-encoding+ .replace(/</g, '<') // Escape less-than signs+ .replace(/>/g, '>') // Escape greater-than signs+ .replace(/"/g, '"') // Escape double quotes+ .replace(/'/g, '''); // Escape single quotes+ };+//convert escaped newlines to real newlineslet rawContent = typeof content != 'string' ? JSON.stringify(content, null, 2) : content;rawContent = rawContent.replace(/\\n/g, '\n');- content = `<textarea readonly class="dbg dbg-textarea text-gray-800">${- rawContent === '' ? '[empty string]' : rawContent- }</textarea>${previewBtn}`;+ // SECURITY: Escape the content before displaying it to prevent XSS+ const escapedContent = escapeHtml(rawContent === '' ? '[empty string]' : rawContent);++ content = `<textarea readonly class="dbg dbg-textarea text-gray-800">${escapedContent}</textarea>${previewBtn}`;return content;}@@ -1287,14 +1302,26 @@ function showOutputInfo(outputEndpoint, outputContent, compName?) {? getFormattedContent(outputContent, compName): outputContent + '';- div.innerHTML = `<button class="pin button primary"><span class="mif-pin icon"></span></button>${formattedContent}`;+ // SECURITY FIX: Create button element properly instead of using innerHTML+ const pinButton = document.createElement('button');+ pinButton.className = 'pin button primary';+ pinButton.textContent = '<span class="mif-pin icon"></span>';++ // Create a container for the formatted content+ const contentContainer = document.createElement('div');+ contentContainer.textContent = formattedContent;++ // Clear the div and append elements safely+ div.textContent = '';div.className = 'dbg-element dbg-output';+ div.appendChild(pinButton);+ div.appendChild(contentContainer);// keep the pinning state if the debugger window is already pinnedconst isPinned = div.closest('.endpoint')?.classList.contains('pinned');togglePinning(div, isPinned ? 'pin' : '');- div.querySelector('.pin').onclick = async (e) => {+ pinButton.onclick = async (e) => {e.stopPropagation();e.stopImmediatePropagation();togglePinning(div, 'toggle');@@ -1354,8 +1381,20 @@ function showInputInfo(inputEndpoint, inputContent) {const formattedContent = getFormattedContent(inputContent);- div.innerHTML = `<button class="pin button primary"><span class="mif-pin icon"></span></button>${formattedContent}`;+ // SECURITY FIX: Create button element properly instead of using innerHTML+ const pinButton = document.createElement('button');+ pinButton.className = 'pin button primary';+ pinButton.textContent = '<span class="mif-pin icon"></span>';++ // Create a container for the formatted content+ const contentContainer = document.createElement('div');+ contentContainer.textContent = formattedContent;++ // Clear the div and append elements safely+ div.textContent = '';div.className = 'dbg-element dbg-output';+ div.appendChild(pinButton);+ div.appendChild(contentContainer);inputEndpoint?.appendChild(div);@@ -1363,7 +1402,7 @@ function showInputInfo(inputEndpoint, inputContent) {const isPinned = div.closest('.endpoint')?.classList.contains('pinned');togglePinning(div, isPinned ? 'pin' : '');- div.querySelector('.pin').onclick = async (e) => {+ pinButton.onclick = async (e) => {e.stopPropagation();e.stopImmediatePropagation();togglePinning(div, 'toggle');