Skip to content
Skillpedia
Websites & UI (frontend)7.8k Β· #13068

panel-component-xss-safe

What it does

This skill guides the AI agent to build dashboard panels in plain TypeScript that show data from outside sources safely. It is for developers whose panels display text from third-party APIs, such as news or calendar events.

When to use it

  • βœ“When a panel shows titles, names or descriptions from an external API.
  • βœ“When untrusted text would be placed into innerHTML on the page.
  • βœ“When you want a standard escaping helper used across all your panels.

Skill link

https://github.com/HKUDS/AgentPilot/blob/main/openspace/legacy/v1/showcase/skills/panel-component-xss-safe/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/HKUDS/AgentPilot/blob/main/openspace/legacy/v1/showcase/skills/panel-component-xss-safe/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute β†’

Example of what to ask your AI

β€œBuild a calendar panel that shows event titles from an outside API. Make sure no event text can inject HTML into the page.”

5 new skills a week. 1 minute to read.

How it works

The agent creates an escape helper that converts ampersands, angle brackets, quotes and apostrophes to HTML entities. Every untrusted value is passed through that helper before it goes into the panel's HTML.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

Panel Component Pattern (XSS-Safe)

Create dashboard panel components using vanilla TypeScript (no framework, no JSX). Each panel is a class extending a Panel base class.

Security note: Panels that consume external API data (calendar events, news feeds, stock names, user-supplied content, etc.) MUST escape all untrusted values before injecting them into innerHTML. Use the esc() helper documented below.

Architecture Overview

Panel (base class)
β”œβ”€β”€ element: HTMLElement (outer container, .panel)
β”‚   β”œβ”€β”€ header: HTMLElement (.panel-header)
β”‚   β”‚   β”œβ”€β”€ headerLeft (.panel-header-left)
β”‚   β”‚   β”‚   β”œβ”€β”€ title (.panel-title)
β”‚   β”‚   β”‚   └── newBadge (.panel-new-badge) [optional]
β”‚   β”‚   β”œβ”€β”€ statusBadge (.panel-data-badge) [optional]
β”‚   β”‚   └── countEl (.panel-count) [optional]
β”‚   β”œβ”€β”€ content: HTMLElement (.panel-content)
β”‚   └── resizeHandle (.panel-resize-handle)

XSS-Safe Rendering: the esc() Helper

Always use esc() when interpolating untrusted data into an HTML string.
Untrusted data includes anything from external APIs: event titles, locations, URLs, names, descriptions, symbols, etc.

Create src/utils/esc.ts:

/**
 * Escapes a value for safe interpolation into an innerHTML string.
 * Converts &, <, >, ", and ' to their HTML entity equivalents.
 *
 * Usage:
 *   this.setContent(`<div class="title">${esc(item.title)}</div>`);
 *
 * Do NOT use for:
 *   - href/src attributes with user-controlled URLs β€” validate scheme instead
 *   - CSS values β€” use a separate sanitizer
 */
export function esc(value: unknown): string {
  return String(value ?? '')
    .replace(/&/g, '&amp;')
    .replace(/</g, '&lt;')
    .replace(/>/g, '&gt;')
    .replace(/"/g, '&quot;')
    .replace(/'/g, '&#39;');
}

When to use esc()

Data source Safe? Action
Hardcoded string literal in source βœ… Safe No escaping needed
Enum / controlled constant βœ… Safe No escaping needed
External API string field (title, name, body…) ❌ Unsafe Use esc()
User input / localStorage value ❌ Unsafe Use esc()
Number/boolean (rendered as text) βœ… Safe String(n) is fine
URL from external API ⚠️ Unsafe Validate scheme + esc()

URL Safety

For URLs from external sources, validate the scheme before injecting:

/** Returns the URL only if it uses http or https; otherwise returns '#'. */
export function safeUrl(raw: unknown): string {
  const s = String(raw ?? '').trim();
  return /^https?:\/\//i.test(s) ? s : '#';
}

Usage: <a href="${safeUrl(item.url)}">${esc(item.title)}</a>


Base Panel Class

Create src/components/Panel.ts:

export interface PanelOptions {
  id: string;
  title: string;
  showCount?: boolean;
  className?: string;
}

export class Panel {
  protected element: HTMLElement;
  protected content: HTMLElement;
  protected header: HTMLElement;
  protected countEl: HTMLElement | null = null;
  protected panelId: string;
  private _fetching = false;

  constructor(options: PanelOptions) {
    this.panelId = options.id;
    this.element = document.createElement('div');
    this.element.className = `panel ${options.className || ''}`;
    this.element.dataset.panel = options.id;

    // Header
    this.header = document.createElement('div');
    this.header.className = 'panel-header';

    const headerLeft = document.createElement('div');
    headerLeft.className = 'panel-header-left';

    const title = document.createElement('span');
    title.className = 'panel-title';
    title.textContent = options.title;  // textContent is always safe
    headerLeft.appendChild(title);
    this.header.appendChild(headerLeft);

    // Count badge (optional)
    if (options.showCount) {
      this.countEl = document.createElement('span');
      this.countEl.className = 'panel-count';
      this.countEl.textContent = '0';
      this.header.appendChild(this.countEl);
    }

    // Content area
    this.content = document.createElement('div');
    this.content.className = 'panel-content';
    this.content.id = `${options.id}Content`;

    this.element.appendChild(this.header);
    this.element.appendChild(this.content);
    this.showLoading();
  }

  public getElement(): HTMLElement { return this.element; }

  public showLoading(message = 'Loading...'): void {
    // message is a hardcoded string β€” no escaping needed here
    this.content.innerHTML = `
      <div class="panel-loading">
 
FAQ

What does the esc helper do?

It converts special characters such as angle brackets and quotes to HTML entities, so they display as text.

Which data needs escaping?

The skill says any untrusted value from an external API, such as titles, locations, URLs and names, must be escaped.

Does this change how panels look?

No, it only changes how text is inserted, so the layout stays the same.

Details

Original description by the author

Create a dashboard panel component using vanilla TypeScript DOM API, following the worldmonitor Panel architecture. Panels have a header with title/count, scrollable content area, loading/error states, and resize handles. Includes XSS-safe rendering pattern with esc() helper for safely interpolating untrusted external API data into innerHTML.

repo: HKUDS/AgentPilot

Popularity

GitHub stars
7.8k
Ranking position
#13068
License
MIT
Updated
11/1/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills