<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>| Name | Role | Status |
|---|---|---|
| Alice | Admin | Active |
| Bob | Editor | Active |
| Carol | Viewer | Inactive |
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.
<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>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
| ID | Name | City |
|---|---|---|
| 1 | Alice | London |
| 2 | Bob | Paris |
| 3 | Carol | Berlin |
<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>| Name | Department | Joined |
|---|---|---|
| Alice | Engineering | 2022-01-15 |
| Bob | Design | 2022-03-20 |
| Carol | Engineering | 2023-06-01 |
<secure-table security-tier="authenticated">
<table slot="table">...</table>
</secure-table>data-tier="sensitive" on the <th> display only the last 4 characters (••••4321). The full value is never written to the DOM.| Name | Role | |
|---|---|---|
| Alice | alice@example.com | Admin |
| Bob | bob@example.com | Editor |
| Carol | carol@example.com | Viewer |
<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>data-tier="critical" are fully replaced with ••••••••. Masked values cannot be selected, copied, or read by page scripts.| Name | API Token | Expires |
|---|---|---|
| Alice | sk-abc123456789 | 2025-12-31 |
| Bob | sk-xyz987654321 | 2025-06-30 |
<!-- data-tier="critical" on a column
fully masks all cell values -->
<th data-key="token" data-tier="critical">
API Token
</th>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.| Name | Score | Level |
|---|---|---|
| Alice | 95 | Senior |
| Bob | 82 | Mid |
| Carol | 91 | Senior |
| Dave | 74 | Junior |
<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>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.| Name | Department | Location |
|---|---|---|
| Alice | Engineering | London |
| Bob | Design | Paris |
| Carol | Engineering | Berlin |
| Dave | Marketing | London |
| Eve | Design | Tokyo |
<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>| Name | City | Status |
|---|---|---|
| Alice | London | Active |
| Bob | Paris | Active |
| Carol | Berlin | Inactive |
| Dave | Tokyo | Active |
| Eve | Sydney | Active |
| Frank | New York | Inactive |
| Grace | Toronto | Active |
| Henry | Dublin | Active |
| Iris | Stockholm | Active |
| Jack | Madrid | Inactive |
| Karen | Vienna | Active |
| Leo | Lisbon | Active |
<!-- 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>| Name | Role | Status | Joined |
|---|---|---|---|
| Alice | Admin | Active | 2022-01 |
| Bob | Editor | Inactive | 2022-03 |
| Carol | Viewer | Active | 2023-06 |
| Dave | Editor | Active | 2023-09 |
| Eve | Viewer | Inactive | 2024-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.
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.
// 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);// 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 ✗| Feature | Public | Authenticated | Sensitive | Critical |
|---|---|---|---|---|
| XSS-safe cell rendering | Yes | Yes | Yes | Yes |
| Column injection prevention | Yes | Yes | Yes | Yes |
| Sort/filter input sanitization | Yes | Yes | Yes | Yes |
| Audit logging | - | Yes | Yes | Yes |
| Sensitive column masking (last 4 visible) | - | - | Yes | Yes |
| Critical column full masking | - | - | - | Yes |
Theming
Secure-UI uses CSS custom properties. Override at :root, per-component, or per-instance.
| Variable | Default | Description |
|---|---|---|
--secure-ui-table-border-color | var(--secure-ui-color-border) | Cell and table border colour |
--secure-ui-table-header-bg | var(--secure-ui-color-bg-secondary) | Header row background |
--secure-ui-table-row-hover | rgba(16,185,129,0.05) | Row hover background |
--secure-ui-table-font-size | var(--secure-ui-font-size-sm) | Table cell font size |
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);
}| Name | Role | Status |
|---|---|---|
| Alice | Admin | Active |
| Bob | Editor | Active |
| Carol | Viewer | Inactive |
Framework Examples
Web Components work natively in all frameworks. No wrappers, no adapters.
<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><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>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
/>
);
}<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>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;
}
}<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>// 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>
}