-
Couldn't load subscription status.
- Fork 64
Panel layout manager #598
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Panel layout manager #598
Conversation
| header.innerHTML = ` | ||
| <div class="sa-panel-layout__item-title">${title}</div> | ||
| <div class="sa-panel-layout__item-coords">${panel.x},${panel.y} | ${panel.width}×${panel.height}</div> | ||
| `; |
Check warning
Code scanning / CodeQL
DOM text reinterpreted as HTML Medium
DOM text
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 1 month ago
How to fix:
The core issue is the unescaped insertion of possibly-untrusted text into an HTML context using .innerHTML. The safest, most robust fix is to escape title for HTML meta-characters (<, >, &, ", etc.) before embedding it into the string. The best way to implement this is to create a utility function to escape HTML, and use it on title in the template string.
Detailed steps:
- Implement an
escapeHtmlfunction in the file (preferably at module-scope if not available elsewhere) that converts"&","<",">",'"', and'to their corresponding HTML entities. - Use
escapeHtml(title)(instead oftitle) in the template literal on line 54, ensuring that any unexpected input is displayed as text, not HTML. - No external dependencies are required for this, and the change should be limited to the scope of the existing method in the file shown.
-
Copy modified lines R20-R32 -
Copy modified line R67
| @@ -17,6 +17,19 @@ | ||
| resizeHandler?: (e: MouseEvent) => void; // Mouse down handler for resizing | ||
| } | ||
|
|
||
| /** | ||
| * Escape a string for insertion into HTML context. | ||
| * Converts &, <, >, ", and ' to HTML entities. | ||
| */ | ||
| function escapeHtml(str: string): string { | ||
| return String(str) | ||
| .replace(/&/g, "&") | ||
| .replace(/</g, "<") | ||
| .replace(/>/g, ">") | ||
| .replace(/"/g, """) | ||
| .replace(/'/g, "'"); | ||
| } | ||
|
|
||
| export class PanelLayoutEngine extends LayoutEngine { | ||
| public static GRID_SIZE = 25; | ||
| public static DEFAULT_COL_COUNT = 2; | ||
| @@ -51,7 +64,7 @@ | ||
| header.className = "sa-panel-layout__item-header"; | ||
| const title = item.dataset.title || (item.querySelector(".sa-question__title") as HTMLElement)?.innerText || "Panel"; | ||
| header.innerHTML = ` | ||
| <div class="sa-panel-layout__item-title">${title}</div> | ||
| <div class="sa-panel-layout__item-title">${escapeHtml(title)}</div> | ||
| <div class="sa-panel-layout__item-coords">${panel.x},${panel.y} | ${panel.width}×${panel.height}</div> | ||
| `; | ||
| item.prepend(header); |
No description provided.