<secure-input>

A drop-in replacement for <input> that moves security enforcement inside a closed Shadow DOM. Scripts, extensions, and devtools cannot read the field value or reach its internal state. Every interaction is measured — focus timing, typing velocity, paste events — and dispatched as a secure-audit event on your server.

<script type="module"
  src="/components/secure-input/secure-input.js">
</script>
View API Reference →
Live Demo

Configurations

security-tier="critical"
The default tier. Autocomplete disabled, rate limiting on, full audit logging. Use for passwords, security questions, and any field that controls access.
<secure-input
  label="Access Token"
  name="token"
  security-tier="critical">
</secure-input>
security-tier="sensitive"
For PII — email, phone, address. Autocomplete disabled, audit logging on. Browser cannot cache the value between sessions.
<secure-input
  label="Email Address"
  name="email"
  type="email"
  security-tier="sensitive"
  required>
</secure-input>
type="password" security-tier="critical"
Value is masked inside the Shadow DOM. autocomplete="new-password" set automatically. Paste events are recorded in the audit log. The plaintext never touches the light DOM.
<secure-input
  label="Password"
  name="password"
  type="password"
  security-tier="critical"
  required>
</secure-input>
security-tier="public"
Browser autocomplete allowed. No rate limiting. XSS sanitization still active. Use for preferences, search fields, and non-sensitive data.
<secure-input
  label="Display Name"
  name="display_name"
  security-tier="public">
</secure-input>
required
Error is shown on blur if the field is empty. Works with native <form> constraint validation and checkValidity().
<secure-input
  label="Company Name"
  name="company"
  required
  security-tier="public">
</secure-input>
minlength / maxlength
Length limits enforced inside the Shadow DOM — not bypassable by setting input.maxLength from outside. Violation is recorded in the audit log.
<secure-input
  label="Username"
  name="username"
  minlength="3"
  maxlength="20"
  security-tier="public">
</secure-input>

Security Features

These are client-side defences. Server-side validation is always the security boundary — these reduce the attack surface and produce a complete interaction record for your server to act on.

Per-field behavioral signals Available on authenticated, sensitive, critical
focusAt Timestamp when the field received focus —
firstKeystrokeAt Timestamp of the first keypress after focus —
dwell Milliseconds spent in the field —
keyCount Total keypresses recorded —
velocity Keystrokes per second — bots type instantly —
pasteDetected Whether the value was pasted rather than typed —
zeroKeystrokeSubmit Field submitted with a value but zero keypresses — flags autofill attacks —
Real-time injection detection Fires secure-threat-detected on every input event

Every keystroke is scanned against 8 patterns. Only the first match per event is reported. The raw field value is never included in the event detail.

el.addEventListener('secure-threat-detected', e => {
  const { fieldName, threatType,
          patternId, tier, timestamp } = e.detail;
  // threatType: 'injection'
  // patternId: e.g. 'script-tag', 'js-protocol'
  // raw value intentionally absent
});
Pattern IDs
script-tag<script tags
js-protocoljavascript: URIs
event-handlerInline handlers — onclick=, onload=
html-injection<img>, <svg>, <iframe>, etc.
css-expressionIE-era expression() CSS
vbscriptvbscript: URIs
data-uri-htmldata:text/html payloads
template-syntax{{...}} template injection probes
Inline threat feedback opt-in via threat-feedback attribute

Add threat-feedback to show an amber inline warning directly below the field when a pattern matches. The message identifies the blocked pattern and security tier. It clears automatically when the input is clean. The underlying secure-threat-detected event fires regardless — silent detection is always on.

<!-- Inline feedback enabled -->
<secure-input
  type="text"
  label="Username"
  name="username"
  security-tier="authenticated"
  threat-feedback>
</secure-input>

<!-- Silent detection only (e.g. code editor) -->
<secure-input
  type="text"
  label="Code"
  name="code">
</secure-input>
Live demo — try <script>alert(1)</script>
FeaturePublicAuthenticatedSensitiveCritical
Closed Shadow DOM isolationYesYesYesYes
XSS sanitizationYesYesYesYes
Real-time injection detectionYesYesYesYes
Inline threat feedback (threat-feedback)Opt-inOpt-inOpt-inOpt-in
Progressive enhancement (no-JS fallback)YesYesYesYes
Behavioral telemetry-YesYesYes
Audit logging-YesYesYes
Autocomplete disabled--YesYes
Rate limiting--YesYes

Theming

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

VariableDefaultDescription
--secure-ui-input-height2.5remInput element height
--secure-ui-input-padding-x0.75remHorizontal padding
--secure-ui-input-font-size0.9375remFont size inside input
--secure-ui-input-border-radius6pxCorner radius
--secure-ui-input-bgvar(--secure-ui-color-bg-primary)Input background color
--secure-ui-input-border-colorvar(--secure-ui-color-border)Default border color
--secure-ui-input-border-color-focusvar(--secure-ui-color-primary)Border color on focus
--secure-ui-input-text-colorvar(--secure-ui-color-text-primary)Input text color
Themed Example
.my-form secure-input {
  --secure-ui-input-border-radius: 2px;
  --secure-ui-input-border-color: #6366f1;
  --secure-ui-input-border-color-focus: #818cf8;
  --secure-ui-input-height: 3rem;
}

Framework Examples

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

Plain HTML html
<!DOCTYPE html>
<html>
<head>
  <script type="module"
    src="/components/secure-input/secure-input.js">
  </script>
</head>
<body>
  <secure-input
    type="email"
    label="Email"
    name="email"
    security-tier="sensitive"
    required>
  </secure-input>
</body>
</html>
React (JSX) tsx
import { useEffect } from 'react';

// Extend JSX types for custom element
declare global {
  namespace JSX {
    interface IntrinsicElements {
      'secure-input': React.DetailedHTMLProps<
        React.HTMLAttributes<HTMLElement> & {
          label?: string;
          name?: string;
          type?: string;
          'security-tier'?: string;
          required?: boolean;
        },
        HTMLElement
      >;
    }
  }
}

export function EmailField() {
  useEffect(() => {
    import('/components/secure-input/secure-input.js');
  }, []);

  return (
    <secure-input
      type="email"
      label="Email"
      name="email"
      security-tier="sensitive"
      required
    />
  );
}
Vue 3 vue
<template>
  <secure-input
    type="email"
    label="Email"
    :name="fieldName"
    security-tier="sensitive"
    required
  />
</template>

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

const fieldName = 'email';

onMounted(() => {
  import('/components/secure-input/secure-input.js');
});
</script>
Angular typescript
import { Component, CUSTOM_ELEMENTS_SCHEMA, OnInit } from '@angular/core';

@Component({
  selector: 'app-email-field',
  template: `
    <secure-input
      type="email"
      label="Email"
      name="email"
      security-tier="sensitive"
      required>
    </secure-input>
  `,
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
})
export class EmailFieldComponent implements OnInit {
  ngOnInit() {
    import('/components/secure-input/secure-input.js');
  }
}
Svelte svelte
<script>
  import { onMount } from 'svelte';

  onMount(() => {
    import('/components/secure-input/secure-input.js');
  });
</script>

<secure-input
  type="email"
  label="Email"
  name="email"
  security-tier="sensitive"
  required>
</secure-input>
Go / Templ templ
templ EmailField(name string, required bool) {
  <secure-input
    type="email"
    label="Email Address"
    name={ name }
    security-tier="sensitive"
    if required {
      required
    }
  ></secure-input>
}