liveBook · Manning

Homograph

As explained in JavaScript in Depth

A visually similar character or string that can be confused with another despite differing in underlying code units or code points.

A homograph is a pair of different characters that appear visually identical. The underlying code points can differ, so ordinary string equality, validation, and uniqueness checks may treat them as distinct. section 2.1.2

Normalization addresses equivalent code-unit sequences, not every visual impersonation. Normalize at system boundaries and before validation; use NFKC for security-critical comparisons, then add explicit homograph detection. section 2.1.2

Practical safeguards include:

  • Normalize usernames before comparing or storing them, so canonically equivalent spellings do not create duplicate identities. section 2.1.2
  • Restrict critical identifiers such as usernames to ASCII when visual impersonation carries significant risk. section 2.1.2
  • Treat Unicode-aware matching separately: JavaScript regular expressions need the u flag to process complete Unicode characters rather than UTF-16 code units. section 2.1.2

Latin and Cyrillic lookalikes

const latin = 'a'; const cyrillic = 'а'; These characters look alike but represent different code points, so a visual comparison can mislead while strict equality distinguishes them. section 2.1.2

How JavaScript in Depth covers it

How deep it goes
Distinguishes visual similarity from encoding equivalence and gives mitigation steps, but does not detail a detection algorithm.
Examples
Uses Latin and Cyrillic a characters plus duplicate-looking usernames to expose deceptive identity comparisons.
What you can do after
Diagnose visually deceptive identifier bugs and apply normalization, ASCII restriction, and additional homograph detection.
How it connects
Connects homographs with Unicode, code points, normalization, input validation, usernames, and regular expressions.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of JavaScript in Depth. The section links point to the parts of the book it draws on.