<secure-select>
A security-hardened dropdown that enforces a closed option allowlist, prevents value injection attacks, and provides full audit logging.
The Problem with Native Select
A native <select> has no client-side allowlist enforcement. Any JavaScript running on the page — including browser extensions, injected scripts, or malicious third-party code — can set the value to anything:
// A native <select> with options: viewer, editor
const select = document.querySelector('select[name="role"]');
// This succeeds silently — no error, no log
select.value = 'admin';
// The form now submits "admin" even though it was never in the options
console.log(select.value); // "admin"How Secure Select Fixes It
On mount, <secure-select> reads every <option value> from the server-rendered HTML and locks them into a private allowlist. From that point, only those values can be selected — programmatically or by the user.
<option> elements at initialization. Any attempt to set a value outside this set is rejected and the field is reset to empty.addOption() pass through the same sanitization pipeline.<select>. JS adds the security layer — the form always works.const select = document.querySelector('secure-select[name="role"]');
// Options are: viewer, editor — set server-side
// Injection attempt
select.value = 'admin';
// Rejected: value is reset to '' and logged
console.log(select.value); // ""
// Audit log records the attempt:
// { action: 'invalid_option_detected', attemptedValue: 'admin' }
const log = select.getAuditLog();Basic Usage
Drop in as a direct replacement for <select>. Options are declared server-side — this is what seeds the allowlist.
<secure-select
label="Role"
name="role"
security-tier="critical"
required
>
<option value="">Select a role</option>
<option value="viewer">Viewer</option>
<option value="editor">Editor</option>
<option value="admin">Administrator</option>
</secure-select>Security Tiers
The security-tier attribute controls validation strictness, autocomplete behaviour, and rate limiting. Default is critical.
Autocomplete: Allowed
Rate limiting: Off
Autocomplete: Disabled
Rate limiting: On
Autocomplete: Disabled
Rate limiting: On, full audit logging
<!-- PUBLIC: General preferences, browser autocomplete allowed -->
<secure-select security-tier="public" label="Theme" name="theme">
<option value="light">Light</option>
<option value="dark">Dark</option>
<option value="system">System</option>
</secure-select>
<!-- CRITICAL: Permission level, autocomplete off, full audit log -->
<secure-select security-tier="critical" label="Access Level" name="access_level">
<option value="viewer">Viewer</option>
<option value="editor">Editor</option>
<option value="admin">Administrator</option>
</secure-select>Dynamic Options
When options must be loaded from an API, use addOption(). Added options are sanitized and registered in the allowlist before the component accepts them as valid selections.
<option> elements are the most secure approach — the allowed set is defined at render time and never travels through client-side JS. Use dynamic loading only when the option list cannot be known at render time.const select = document.querySelector('secure-select[name="country"]');
const response = await fetch('/api/countries');
const countries = await response.json();
select.clearOptions();
select.addOption('', 'Select a country');
for (const { code, name } of countries) {
// Values are sanitized inside addOption() before entering the allowlist
select.addOption(code, name);
}API Reference
Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
security-tier | string | "critical" | Validation strictness: public, sensitive, critical |
name | string | - | Form field name |
label | string | - | Visible label text (also sets aria-label when no visible label) |
required | boolean | false | Field is required |
disabled | boolean | false | Disable the select |
multiple | boolean | false | Allow multiple selections — all selected values are validated against the allowlist |
size | number | - | Number of visible options (listbox mode) |
Properties
Methods
'error'.reportError()Events
| Event | Detail | Description |
|---|---|---|
secure-select-change | { name, value, tier } | Fired on valid selection change. value is a string array for multi-select, a string for single-select. Not fired when an injection attempt is blocked. |
secure-audit | { event, tier, timestamp, data? } | Fired on every audit entry |