<secure-table>

A data table component with XSS-safe cell rendering, column injection prevention, and sanitized sort and filter inputs. Supports pagination, configurable page sizes, and optional sort and filter UI. All data is treated as untrusted and escaped before rendering.

<script type="module"
  src="/components/secure-table/secure-table.js">
</script>
View API Reference →
Live Demo
NameRoleStatus
AliceAdminActive
BobEditorActive
CarolViewerInactive

How to Provide Data

<secure-table> supports two data sources. The slotted HTML approach provides progressive enhancement — the table is readable without JavaScript. The programmatic approach is suited for dynamic or framework-managed data.

Slotted HTML (recommended)
Server renders a standard <table slot="table">. The component reads it on mount, builds an internal data model, then replaces the slot with an enhanced UI. Works without JavaScript.

✓  Progressive enhancement — readable without JS

<!-- Table data is in the light DOM.
     Component reads it on mount, then
     replaces it with an enhanced UI. -->
<secure-table security-tier="public" sortable>
  <table slot="table">
    <thead>
      <tr>
        <th data-key="name">Name</th>
        <th data-key="email">Email</th>
        <th data-key="role">Role</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Alice</td>
        <td>alice@example.com</td>
        <td>Admin</td>
      </tr>
    </tbody>
  </table>
</secure-table>
Programmatic (JavaScript)
Set columns and data as JS properties after the component connects. Use this for SPA data flows where rows arrive asynchronously or update reactively.

↻  Reactive — reassign .data to update the table

// Set columns and data via JS properties
// after the component is connected to the DOM.
const table = document.querySelector('#myTable');

table.columns = [
  { key: 'name',  label: 'Name',  sortable: true },
  { key: 'email', label: 'Email', sortable: true },
  { key: 'role',  label: 'Role',  sortable: true },
];

table.data = [
  { name: 'Alice', email: 'alice@example.com', role: 'Admin' },
  { name: 'Bob',   email: 'bob@example.com',   role: 'Editor' },
];

Configurations

security-tier="public"
XSS sanitization on all cells. No audit log. Use for catalog listings, search results, and reference data accessible without authentication.
IDNameCity
1AliceLondon
2BobParis
3CarolBerlin
<secure-table security-tier="public">
  <table slot="table">
    <thead><tr>
      <th data-key="id">ID</th>
      <th data-key="name">Name</th>
    </tr></thead>
    <tbody>
      <tr><td>1</td><td>Alice</td></tr>
    </tbody>
  </table>
</secure-table>
security-tier="authenticated"
Adds audit logging on sort, filter, and access events. Use for user lists, order history, and records only accessible to authenticated users.
NameDepartmentJoined
AliceEngineering2022-01-15
BobDesign2022-03-20
CarolEngineering2023-06-01
<secure-table security-tier="authenticated">
  <table slot="table">...</table>
</secure-table>
security-tier="sensitive" — column masking
Columns marked data-tier="sensitive" on the <th> display only the last 4 characters (••••4321). The full value is never written to the DOM.
NameEmailRole
Alicealice@example.comAdmin
Bobbob@example.comEditor
Carolcarol@example.comViewer
<secure-table security-tier="sensitive">
  <table slot="table">
    <thead><tr>
      <th data-key="name">Name</th>
      <!-- data-tier on th masks this column -->
      <th data-key="email" data-tier="sensitive">
        Email
      </th>
    </tr></thead>
    ...
  </table>
</secure-table>
security-tier="critical" — full masking
Columns marked data-tier="critical" are fully replaced with ••••••••. Masked values cannot be selected, copied, or read by page scripts.
NameAPI TokenExpires
Alicesk-abc1234567892025-12-31
Bobsk-xyz9876543212025-06-30
<!-- data-tier="critical" on a column
     fully masks all cell values -->
<th data-key="token" data-tier="critical">
  API Token
</th>
sortable
Add data-sortable="true" to individual <th> elements to enable click-to-sort on those columns. Sort state is reflected in column headers. Values sort as strings by default.
NameScoreLevel
Alice95Senior
Bob82Mid
Carol91Senior
Dave74Junior
<secure-table security-tier="public" sortable>
  <table slot="table">
    <thead><tr>
      <th data-key="name" data-sortable="true">
        Name
      </th>
      <th data-key="score" data-sortable="true">
        Score
      </th>
    </tr></thead>
    ...
  </table>
</secure-table>
filterable
Adds a search input above the table. data-filterable="true" on a <th> includes that column in the match. The filter input is sanitized before matching — XSS payloads entered as search terms are neutralized.
NameDepartmentLocation
AliceEngineeringLondon
BobDesignParis
CarolEngineeringBerlin
DaveMarketingLondon
EveDesignTokyo
<secure-table security-tier="public" filterable>
  <table slot="table">
    <thead><tr>
      <!-- data-filterable includes this column -->
      <th data-key="name" data-filterable="true">
        Name
      </th>
      <!-- location column excluded from search -->
      <th data-key="location">Location</th>
    </tr></thead>
    ...
  </table>
</secure-table>
paginated
Pagination activates automatically when row count exceeds the configured page size (default 10). Page controls appear below the table. Works with both slotted and programmatic data.
NameCityStatus
AliceLondonActive
BobParisActive
CarolBerlinInactive
DaveTokyoActive
EveSydneyActive
FrankNew YorkInactive
GraceTorontoActive
HenryDublinActive
IrisStockholmActive
JackMadridInactive
KarenViennaActive
LeoLisbonActive
<!-- Pagination activates automatically
     when row count exceeds page size (default 10).
     12 rows below → pagination shown. -->
<secure-table security-tier="public"
  sortable filterable>
  <table slot="table">
    <thead>...</thead>
    <tbody>
      <!-- 12 rows -->
    </tbody>
  </table>
</secure-table>
sortable + filterable combined
All three features active together. The filter reduces the visible row set first, then sort is applied to the filtered result. Pagination reflects the filtered count.
NameRoleStatusJoined
AliceAdminActive2022-01
BobEditorInactive2022-03
CarolViewerActive2023-06
DaveEditorActive2023-09
EveViewerInactive2024-01
<secure-table
  security-tier="authenticated"
  sortable
  filterable>
  <table slot="table">...</table>
</secure-table>

Security Features

Security is enforced server-side. These features are client-side complements that reduce attack surface.

XSS-safe rendering + column injection prevention All tiers

The component never writes cell values directly to the DOM. All data passes through a text-content assignment — HTML entities are encoded before the cell is rendered. For slotted tables, the column schema is locked at mount time from the server-rendered <th data-key> elements. Attempts to inject additional columns via DOM manipulation after mount are ignored — only keys in the locked schema are rendered.

Injection attempt
// Attacker adds a new column to the DOM
const thead = document.querySelector('tr');
const th = document.createElement('th');
th.dataset.key = 'injectedCol';
th.textContent = '<script>alert(1)</script>';
thead.appendChild(th);
Result
// Column schema is frozen at mount time.
// Columns added after mount are not rendered.
// Cell values are always text-content assigned:
//   cell.textContent = value  ✓
// Never:
//   cell.innerHTML = value    ✗
FeaturePublicAuthenticatedSensitiveCritical
XSS-safe cell renderingYesYesYesYes
Column injection preventionYesYesYesYes
Sort/filter input sanitizationYesYesYesYes
Audit logging-YesYesYes
Sensitive column masking (last 4 visible)--YesYes
Critical column full masking---Yes

Theming

Secure-UI uses CSS custom properties. Override at :root, per-component, or per-instance.

VariableDefaultDescription
--secure-ui-table-border-colorvar(--secure-ui-color-border)Cell and table border colour
--secure-ui-table-header-bgvar(--secure-ui-color-bg-secondary)Header row background
--secure-ui-table-row-hoverrgba(16,185,129,0.05)Row hover background
--secure-ui-table-font-sizevar(--secure-ui-font-size-sm)Table cell font size
Themed Example
secure-table {
  --secure-ui-table-header-bg: rgba(99, 102, 241, 0.15);
  --secure-ui-table-border-color: rgba(99, 102, 241, 0.3);
  --secure-ui-table-row-hover: rgba(99, 102, 241, 0.05);
}
NameRoleStatus
AliceAdminActive
BobEditorActive
CarolViewerInactive

Framework Examples

Web Components work natively in all frameworks. No wrappers, no adapters.

Plain HTML — slotted (recommended) html
<script type="module"
  src="/components/secure-table/secure-table.js">
</script>

<!-- Server renders the <table>; the component
     reads it on mount and enhances it. -->
<secure-table security-tier="authenticated" sortable filterable>
  <table slot="table">
    <thead>
      <tr>
        <th data-key="name"  data-sortable="true" data-filterable="true">Name</th>
        <th data-key="email" data-sortable="true" data-filterable="true">Email</th>
        <th data-key="role"  data-sortable="true">Role</th>
      </tr>
    </thead>
    <tbody>
      <tr><td>Alice</td><td>alice@example.com</td><td>Admin</td></tr>
      <tr><td>Bob</td>  <td>bob@example.com</td>  <td>Editor</td></tr>
    </tbody>
  </table>
</secure-table>
Plain HTML — programmatic html
<script type="module">
  import '/components/secure-table/secure-table.js';

  const table = document.querySelector('#userTable');
  table.columns = [
    { key: 'name',  label: 'Name',  sortable: true, filterable: true },
    { key: 'email', label: 'Email', sortable: true },
    { key: 'role',  label: 'Role',  sortable: true },
  ];
  table.data = [
    { name: 'Alice', email: 'alice@example.com', role: 'Admin' },
    { name: 'Bob',   email: 'bob@example.com',   role: 'Editor' },
  ];
</script>

<secure-table id="userTable"
  security-tier="authenticated"
  sortable filterable>
</secure-table>
React (JSX) tsx
import { useEffect, useRef } from 'react';

const COLUMNS = [
  { key: 'name',  label: 'Name',  sortable: true, filterable: true },
  { key: 'email', label: 'Email', sortable: true },
  { key: 'role',  label: 'Role',  sortable: true },
];

export function UserTable({ users }) {
  const ref = useRef(null);

  useEffect(() => {
    import('/components/secure-table/secure-table.js').then(() => {
      if (ref.current) {
        ref.current.columns = COLUMNS;
        ref.current.data = users;
      }
    });
  }, [users]);

  return (
    <secure-table
      ref={ref}
      security-tier="authenticated"
      sortable
      filterable
    />
  );
}
Vue 3 vue
<template>
  <secure-table
    ref="tableEl"
    security-tier="authenticated"
    sortable
    filterable>
  </secure-table>
</template>

<script setup>
import { ref, onMounted, watch } from 'vue';

const props = defineProps({ rows: Array });
const tableEl = ref(null);

const columns = [
  { key: 'name',  label: 'Name',  sortable: true, filterable: true },
  { key: 'email', label: 'Email', sortable: true },
  { key: 'role',  label: 'Role',  sortable: true },
];

onMounted(async () => {
  await import('/components/secure-table/secure-table.js');
  tableEl.value.columns = columns;
  tableEl.value.data    = props.rows;
});

watch(() => props.rows, (rows) => {
  if (tableEl.value) tableEl.value.data = rows;
});
</script>
Angular typescript
import {
  Component, Input, AfterViewInit,
  ElementRef, ViewChild,
  CUSTOM_ELEMENTS_SCHEMA
} from '@angular/core';

@Component({
  selector: 'app-user-table',
  template: `
    <secure-table
      #tableEl
      security-tier="authenticated"
      sortable filterable>
    </secure-table>
  `,
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
})
export class UserTableComponent implements AfterViewInit {
  @Input() rows: Record<string, unknown>[] = [];
  @ViewChild('tableEl') tableEl!: ElementRef;

  private columns = [
    { key: 'name',  label: 'Name',  sortable: true, filterable: true },
    { key: 'email', label: 'Email', sortable: true },
    { key: 'role',  label: 'Role',  sortable: true },
  ];

  async ngAfterViewInit() {
    await import('/components/secure-table/secure-table.js');
    this.tableEl.nativeElement.columns = this.columns;
    this.tableEl.nativeElement.data    = this.rows;
  }
}
Svelte svelte
<script>
  import { onMount } from 'svelte';
  export let rows = [];

  let tableEl;
  const columns = [
    { key: 'name',  label: 'Name',  sortable: true, filterable: true },
    { key: 'email', label: 'Email', sortable: true },
    { key: 'role',  label: 'Role',  sortable: true },
  ];

  onMount(async () => {
    await import('/components/secure-table/secure-table.js');
    tableEl.columns = columns;
    tableEl.data    = rows;
  });

  $: if (tableEl) tableEl.data = rows;
</script>

<secure-table
  bind:this={tableEl}
  security-tier="authenticated"
  sortable filterable>
</secure-table>
Go / Templ — slotted templ
// Pass rows from your handler — no JS required.
// The component reads the slotted <table> on mount.
templ UserTable(users []User) {
  <secure-table security-tier="authenticated" sortable filterable>
    <table slot="table">
      <thead>
        <tr>
          <th data-key="name"  data-sortable="true">Name</th>
          <th data-key="email" data-sortable="true">Email</th>
          <th data-key="role"  data-sortable="true">Role</th>
        </tr>
      </thead>
      <tbody>
        for _, u := range users {
          <tr>
            <td>{ u.Name }</td>
            <td>{ u.Email }</td>
            <td>{ u.Role }</td>
          </tr>
        }
      </tbody>
    </table>
  </secure-table>
}