Skip to main content

Module github

Module github 

Source
Expand description

GitHub.com official anchor generation with security hardening

This module implements the exact anchor generation algorithm used by GitHub.com, verified through comprehensive testing with GitHub Gists, with comprehensive security hardening against injection attacks and DoS vectors.

Algorithm verified against GitHub.com (not third-party packages):

  1. Input validation and size limits (max 10KB)
  2. Unicode normalization (NFC) to prevent homograph attacks
  3. Dangerous Unicode filtering (RTL override, zero-width, control chars)
  4. Lowercase conversion
  5. Markdown formatting removal (*, `, []) with ReDoS-safe patterns
  6. Multi-character pattern replacement (–>, <->, ==>, ->)
  7. Special symbol replacement (& → –, © → –)
  8. Character processing (preserve letters, digits, underscores, hyphens)
  9. Space → single hyphen, emojis → single hyphen
  10. No leading/trailing trimming (unlike kramdown)

Security measures implemented:

  • Input size limits to prevent memory exhaustion
  • Unicode normalization to prevent homograph attacks
  • Bidirectional text injection prevention
  • Zero-width character stripping
  • Control character filtering
  • ReDoS-resistant regex patterns with complexity limits
  • Comprehensive emoji detection including country flags and keycaps

Functions§

heading_to_fragment
Generate GitHub.com style anchor fragment from heading text with security hardening