Skip to content

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.

Revert "Implement HTML escaping in debugger to prevent XSS vulnerabilities (#77)" (#122)

Ahmed Essam4b5f313dfc96
diff --git a/packages/app/src/builder-ui/debugger.ts b/packages/app/src/builder-ui/debugger.ts
index 28cf0433..607fc410 100644
--- a/packages/app/src/builder-ui/debugger.ts
+++ b/packages/app/src/builder-ui/debugger.ts
@@ -927,28 +927,13 @@ 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, '&amp;') // Must be first to avoid double-encoding
- .replace(/</g, '&lt;') // Escape less-than signs
- .replace(/>/g, '&gt;') // Escape greater-than signs
- .replace(/"/g, '&quot;') // Escape double quotes
- .replace(/'/g, '&#39;'); // Escape single quotes
- };
-
//convert escaped newlines to real newlines
let rawContent = typeof content != 'string' ? JSON.stringify(content, null, 2) : content;
rawContent = rawContent.replace(/\\n/g, '\n');
- // 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}`;
+ content = `<textarea readonly class="dbg dbg-textarea text-gray-800">${
+ rawContent === '' ? '[empty string]' : rawContent
+ }</textarea>${previewBtn}`;
return content;
}
@@ -1302,26 +1287,14 @@ function showOutputInfo(outputEndpoint, outputContent, compName?) {
? getFormattedContent(outputContent, compName)
: outputContent + '';
- // 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.innerHTML = `<button class="pin button primary"><span class="mif-pin icon"></span></button>${formattedContent}`;
div.className = 'dbg-element dbg-output';
- div.appendChild(pinButton);
- div.appendChild(contentContainer);
// keep the pinning state if the debugger window is already pinned
const isPinned = div.closest('.endpoint')?.classList.contains('pinned');
togglePinning(div, isPinned ? 'pin' : '');
- pinButton.onclick = async (e) => {
+ div.querySelector('.pin').onclick = async (e) => {
e.stopPropagation();
e.stopImmediatePropagation();
togglePinning(div, 'toggle');
@@ -1381,20 +1354,8 @@ function showInputInfo(inputEndpoint, inputContent) {
const formattedContent = getFormattedContent(inputContent);
- // 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.innerHTML = `<button class="pin button primary"><span class="mif-pin icon"></span></button>${formattedContent}`;
div.className = 'dbg-element dbg-output';
- div.appendChild(pinButton);
- div.appendChild(contentContainer);
inputEndpoint?.appendChild(div);
@@ -1402,7 +1363,7 @@ function showInputInfo(inputEndpoint, inputContent) {
const isPinned = div.closest('.endpoint')?.classList.contains('pinned');
togglePinning(div, isPinned ? 'pin' : '');
- pinButton.onclick = async (e) => {
+ div.querySelector('.pin').onclick = async (e) => {
e.stopPropagation();
e.stopImmediatePropagation();
togglePinning(div, 'toggle');