Unicode confusables can make two different strings look identical or nearly identical. This guide provides a practical checklist for detecting lookalike characters in usernames, domains, source code, and other developer workflows—while preserving legitimate multilingual text.
Overview
A Unicode confusable is a character that resembles another character in a particular font, script, or writing context. Latin a and Cyrillic а are different code points, for example, even though they can appear indistinguishable. Similar relationships exist among Latin, Greek, Cyrillic, mathematical, fullwidth, and other characters.
A homoglyph attack uses these visual similarities to make an identifier, domain, display name, file, or code element appear familiar. The risk is not limited to phishing. Lookalike characters can also cause account collisions, misleading logs, confusing support investigations, or review errors in source code.
Detection should not mean rejecting every non-ASCII string. Multilingual users need legitimate names, addresses, content, and identifiers. A safer approach is layered review:
- Preserve the original string exactly as entered.
- Normalize or canonicalize it according to the field's rules.
- Inspect scripts, characters, and confusable relationships.
- Apply a context-specific policy, such as warning, review, or rejection.
- Show enough diagnostic detail for a human or administrator to verify the result.
Normalization is useful, but it is not a complete confusable detector. NFC or NFKC may resolve some equivalent or compatibility forms; it does not make Cyrillic and Latin letters the same, and it should not silently replace the value used for display or auditing. Keep a canonical representation and the original input as separate concepts.
Checklist by scenario
Usernames and account identifiers
- Define the identifier policy first. Decide whether usernames may contain one script, a defined set of scripts, or any Unicode letters. Document whether spaces, marks, emoji, punctuation, and compatibility characters are permitted.
- Check for mixed scripts. A username that combines Latin and Cyrillic characters deserves review, especially when the scripts are not expected for the product's audience. Mixed-script use is a signal, not automatic proof of abuse; many real names and language conventions require more than one script.
- Generate a diagnostic view. For suspicious values, show each character, its code point, Unicode name when available, script, and a readable escaped form such as
U+0430. This makes invisible differences visible to reviewers. - Compare against existing identities. Use a carefully defined skeleton or confusable comparison for collision checks, but do not replace the stored username with the skeleton. A comparison result should trigger a policy decision rather than silently merge accounts.
- Protect sensitive actions. Require an additional confirmation when changing a username, creating an administrator identity, or registering a name that resembles an existing privileged account.
Internationalized domain names
- Separate Unicode display from DNS form. Domains may be displayed as Unicode while being represented in an ASCII-compatible form for DNS processing. Use a standards-compliant IDNA implementation rather than hand-written conversion logic.
- Apply a display policy. Browsers and applications commonly make decisions about when a domain is safe to display in Unicode and when an ASCII or escaped representation is clearer. Your application should make an explicit choice for links, email previews, logs, and administrative screens.
- Inspect the registrable domain. Do not judge only the full visual string. Check the relevant domain boundary, label by label, and preserve the actual host used for navigation.
- Make warnings actionable. If a host resembles another host, show the exact domain, not just a generic warning. Avoid presenting a suspicious Unicode label as trusted branding.
Source code, configuration, and review tools
- Scan identifiers, comments, strings, and filenames. Lookalikes in comments can mislead reviewers; lookalikes in identifiers can alter which variable or function is referenced.
- Flag mixed scripts and unusual characters. Establish project-specific allowances instead of imposing an ASCII-only rule on every file. A localization resource and a security-sensitive module may need different policies.
- Reveal invisible and directional characters. Confusables are different from bidirectional control characters, but both can make code difficult to inspect. Use a diagnostic display for control characters, combining marks, and direction changes. See the guide to debugging bidirectional Unicode text for the related problem.
- Review diffs in a character-aware interface. A code review should offer code-point or escaped views when a line contains suspicious characters, rather than relying only on rendered glyphs.
Text fields and search
- Keep the original user text for display and audit trails.
- Use a separate search or comparison form only when its normalization and case-folding rules are appropriate for the language.
- Do not use a visual confusable skeleton as the sole authorization, identity, or moderation key.
What to double-check
Before shipping a detector, verify the behavior of the actual language runtime and libraries in your stack. Unicode data, regular-expression support, case handling, and script properties can vary by runtime version. Test the exact deployment environment rather than assuming that a development machine and production service use identical Unicode data. The Unicode version compatibility guide is useful when comparing browsers, JavaScript engines, ICU, and regular expressions.
- Normalization: Decide whether the field uses NFC, NFKC, or no normalization. Record why. Compatibility normalization can change distinctions that are meaningful to a user.
- Case handling: Do not treat simple lowercase conversion as universal case folding. Locale-sensitive behavior and language-specific casing can affect comparisons.
- Script detection: Confirm whether the library reports script extensions, inherited marks, and common punctuation consistently.
- Confusable data: Pin or review the data and library version used for confusable mappings. Treat mappings as detection input, not as a replacement alphabet.
- Rendering: Test more than one font and platform. Two characters may look alike in one font and distinct in another, or the reverse.
- Logging: Log the original value, a safely escaped diagnostic form, and the policy decision. Avoid logging sensitive data unnecessarily.
For implementation, Unicode property escapes can help identify scripts and character categories where the target language supports them. They are only one part of the workflow: a regular expression can flag a pattern, but it does not decide whether that pattern is legitimate for a particular name or language. Use a maintained Unicode-aware library for the rest of the analysis and test it with a representative corpus. A Unicode test corpus should include accented text, combining marks, CJK text, right-to-left text, mixed punctuation, and intentionally suspicious lookalikes.
Common mistakes
- Allowing anything because it is valid Unicode. Unicode validity only says that a string can be represented; it does not say that the string is safe for an identifier or trustworthy in context.
- Rejecting all non-ASCII input. This avoids some lookalikes but creates unnecessary barriers for international users and does not solve every visual deception problem.
- Relying on normalization alone. Normalization handles equivalence rules, not every visual similarity.
- Comparing rendered text only. Store and inspect code points. Rendering depends on fonts, operating systems, and fallback behavior.
- Using one global rule. A domain label, username, source-code identifier, comment, and free-form message have different risk profiles.
- Silently rewriting input. Automatic substitution can corrupt names and make audit trails unreliable. Prefer a warning, a review queue, or a clearly explained rejection.
- Forgetting accessibility and localization. A warning must be understandable without requiring users to identify scripts or code points themselves. Provide the original value and a readable explanation.
When to revisit
Revisit your confusable policy before seasonal planning cycles, account-system changes, domain migrations, major editor or CI changes, and updates to language runtimes or Unicode data. Also review it after a phishing investigation, a suspicious account report, or the addition of a new supported language.
Use this short review sequence:
- Collect examples from real product data and from a controlled Unicode test corpus.
- Confirm the Unicode, ICU, IDNA, regex, and rendering behavior in each supported environment.
- Recheck mixed-script, normalization, and confusable policies for every identifier type.
- Test warnings, review queues, logs, exports, and administrative screens—not just the registration form.
- Document exceptions for legitimate multilingual use and assign an owner for future updates.
Keep the checklist close to code review and identity-management workflows. When the inputs, libraries, or supported scripts change, rerun the tests and review the policy rather than assuming yesterday's detection rules still fit.