惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
News and Events Feed by Topic
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
T
Threat Research - Cisco Blogs
Cloudbric
Cloudbric
Recent Commits to openclaw:main
Recent Commits to openclaw:main
I
Intezer
Attack and Defense Labs
Attack and Defense Labs
P
Privacy International News Feed
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
L
Lohrmann on Cybersecurity
C
Cybersecurity and Infrastructure Security Agency CISA
V2EX - 技术
V2EX - 技术
AWS News Blog
AWS News Blog
O
OpenAI News
L
LINUX DO - 最新话题
N
News | PayPal Newsroom
PCI Perspectives
PCI Perspectives
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
Troy Hunt's Blog
Latest news
Latest news
D
Darknet – Hacking Tools, Hacker News & Cyber Security
A
Arctic Wolf
Spread Privacy
Spread Privacy
G
GRAHAM CLULEY
T
Tor Project blog
博客园_首页
Know Your Adversary
Know Your Adversary
有赞技术团队
有赞技术团队
S
Secure Thoughts
美团技术团队
Apple Machine Learning Research
Apple Machine Learning Research
爱范儿
爱范儿
T
Tailwind CSS Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
V
Visual Studio Blog
J
Java Code Geeks
Cisco Talos Blog
Cisco Talos Blog
Schneier on Security
Schneier on Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Security Affairs
Jina AI
Jina AI
人人都是产品经理
人人都是产品经理
雷峰网
雷峰网
宝玉的分享
宝玉的分享
量子位
Last Week in AI
Last Week in AI
月光博客
月光博客
罗磊的独立博客
S
SegmentFault 最新的问题

Aaron Gustafson: Latest Posts & Links

LLM biased against accessible code (Claude Code issue #56079) :: Aaron Gustafson Can Your AI Pass the Accessibility Test? :: Aaron Gustafson Can Your AI Pass the Accessibility Test? :: Aaron Gustafson Fixing Accessibility After the Fact Is Too Late :: Aaron Gustafson Easy Data-entry Verification with a Web Component :: Aaron Gustafson Artificial Intelligence Has One Chance To Get Accessibility Right :: Aaron Gustafson Building a general-purpose accessibility agent—and what we learned in the process :: Aaron Gustafson Fixing Accessibility After the Fact Is Too Late :: Aaron Gustafson AI companies will fail. We can salvage something from the wreckage :: Aaron Gustafson Accessible faux-nested interactive controls :: Aaron Gustafson AI-assisted coding transforms PDF to web app using NYS Design System :: Aaron Gustafson Modern CSS Feature Support For Shadow DOM :: Aaron Gustafson AI is locking people out. At Scale. :: Aaron Gustafson The Incredible Overcomplexity of the Shadcn Radio Button :: Aaron Gustafson Accessibility in the End of Deterministic Design (Again) :: Aaron Gustafson Making keyboard navigation effortless :: Aaron Gustafson The WebAIM Million: The 2026 report on the accessibility of the top 1,000,000 home pages :: Aaron Gustafson Under the hood of MDN’s new frontend :: Aaron Gustafson Endgame for the Open Web :: Aaron Gustafson slideVars :: Aaron Gustafson AI is accidently making documentation accessible :: Aaron Gustafson Design systems can’t automate away all of your accessibility considerations :: Aaron Gustafson The Power of ‘No’ in Internet Standards :: Aaron Gustafson Nice Select :: Aaron Gustafson Visual Validation Feedback for Form Fields :: Aaron Gustafson Never Lose Form Progress Again :: Aaron Gustafson Different contexts, different tools, same person :: Aaron Gustafson Accessibility Assistant for Figma v52 :: Aaron Gustafson Some blind fans to experience Super Bowl with tactile device that tracks ball :: Aaron Gustafson Why we teach our students progressive enhancement :: Aaron Gustafson Repeatable Form Fields Made Simple :: Aaron Gustafson A Production-Ready Web Component Starter Template :: Aaron Gustafson Fullscreen Video and Iframes Made Easy :: Aaron Gustafson Dynamic Datalist: Autocomplete from an API :: Aaron Gustafson Lazy Loading Images Based on Screen Size :: Aaron Gustafson Forrester Research: As technology has evolved, so has the need for accessibility :: Aaron Gustafson Creating a more accessible web with ARIA Notify :: Aaron Gustafson Optimizing Your Codebase for AI Coding Agents :: Aaron Gustafson A Web Component for Conditionally Displaying Fields :: Aaron Gustafson Default Isn’t Design :: Aaron Gustafson Identifying Accessibility Data Gaps in CodeGen Models :: Aaron Gustafson Designing for Distress: Understanding Users in Crisis :: Aaron Gustafson Why I'm Betting Against AI Agents in 2025 (Despite Building Them) :: Aaron Gustafson Why AI Won’t Destroy Us with Microsoft’s Brad Smith :: Aaron Gustafson Learning Web Design, 6th Edition is out! :: Aaron Gustafson
A Web Component for Obfuscating Form Fields :: Aaron Gustafson
Aaron Gustafson · 2025-12-06 · via Aaron Gustafson: Latest Posts & Links

We have the password reveal pattern for passwords, but what about other sensitive fields that need to be readable while editing and obfuscated while at rest? The form-obfuscator web component does exactly that.

Basic usage

Wrap any text field in the component and it will automatically obfuscate the value when the field loses focus:

<form-obfuscator>
  <label for="secret-key-1">What was your first pet’s name?</label>
  <input type="text" id="secret-key-1" name="secret-key-1" />
</form-obfuscator>

When users click into the field, they see the actual value. When they click away, it’s replaced with asterisks (*). The real value is preserved in a hidden field for form submission.

Custom obfuscation characters

If you don’t like asterisks, you can specify any character you like:

<form-obfuscator character="">
  <label for="account">Account Number</label>
  <input type="text" id="account" name="account" />
</form-obfuscator>

Or get creative:

<form-obfuscator character="🤐">
  <label for="ssn">Social Security Number</label>
  <input type="text" id="ssn" name="ssn" />
</form-obfuscator>

Pattern-based obfuscation

Sometimes you want to show part of the value while hiding the rest. The pattern attribute lets you specify which characters to keep visible:

<form-obfuscator pattern="\d{4}$">
  <label for="ssn">Social Security Number</label>
  <input type="text" id="ssn" name="ssn" />
</form-obfuscator>

This keeps the last four digits visible while replacing everything else with your obfuscation character. Perfect for Social Security Numbers, credit cards, or phone numbers where showing the last few digits helps users confirm they’ve entered the right value.

Limiting displayed characters

Use the maxlength attribute to cap how many characters appear when obfuscated:

<form-obfuscator maxlength="4">
  <label for="password">Password</label>
  <input type="text" id="password" name="password" />
</form-obfuscator>

Even if the user enters a 20-character value, only four asterisks will be displayed when the field is obfuscated. This prevents giving away information about the length of the information entered.

Custom replacement functions

For complete control, you can provide a JavaScript function via the replacer attribute:

<script>
  window.emailReplacer = function () {
    var username = arguments[0][1];
    var domain = arguments[0][2];
    return username.replace(/./g, "*") + domain;
  };
</script>

<form-obfuscator
  pattern="^(.*?)(@.+)$"
  replacer="return emailReplacer(arguments)"
>
  <label for="email">Email Address</label>
  <input type="text" id="email" name="email" value="user@example.com" />
</form-obfuscator>

This example uses a pattern to separate the username from the domain, then obfuscates only the username portion, leaving @example.com visible.

Here’s another practical example for credit cards:

<script>
  function cardNumberReplacer() {
    var beginning = arguments[0][1];
    var final_digits = arguments[0][2];
    return beginning.replace(/\d/g, "*") + final_digits;
  }
</script>

<form-obfuscator
  pattern="^((?:[\d]+\-)+)(\d+)$"
  replacer="return cardNumberReplacer(arguments)"
>
  <label for="cc">Credit Card</label>
  <input type="text" id="cc" name="cc" value="1234-5678-9012-3456" />
</form-obfuscator>

This displays as ****-****-****-3456, showing only the last group of digits.

Combining attributes

You can combine these attributes for sophisticated obfuscation patterns:

<form-obfuscator pattern="\d{4}$" character="" maxlength="16">
  <label for="card">Credit Card</label>
  <input type="text" id="card" name="card" />
</form-obfuscator>

This keeps the last 4 digits visible, uses bullets for obfuscation, and limits the display to 16 characters total.

Event handling

The component dispatches custom events when values are hidden or revealed:

const obfuscator = document.querySelector("form-obfuscator");

obfuscator.addEventListener("form-obfuscator:hide", (e) => {
  console.log("Field obfuscated:", e.detail.field.value);
});

obfuscator.addEventListener("form-obfuscator:reveal", (e) => {
  console.log("Field revealed:", e.detail.field.value);
});

You can access both the visible field and the hidden field through event.detail.field and event.detail.hidden respectively.

How it works

The component creates a hidden input field to store the actual value for form submission. When the visible field loses focus, it:

  1. Copies the current value to the hidden field
  2. Applies your obfuscation rules to create the display value
  3. Updates the visible field with the obfuscated value
  4. Dispatches the form-obfuscator:hide event

When the field gains focus, it:

  1. Restores the real value from the hidden field
  2. Updates the visible field
  3. Dispatches the form-obfuscator:reveal event

The source order ensures the hidden field is the one that gets submitted with the form.

Progressive enhancement

The component makes no assumptions about your markup—it works with any text-style input element. If JavaScript fails to load, the field behaves like a normal input, which is exactly what you want. Users can still enter and submit values; they just won’t get the obfuscation behavior.

Demo

I’ve created a comprehensive demo page showing the various configuration options over on GitHub:

Grab it

Check out the full project over on GitHub or install via npm:

npm install @aarongustafson/form-obfuscator

Import and use:

import "@aarongustafson/form-obfuscator";

No dependencies, just a straightforward way to add field obfuscation to your forms.