Design Decision: Raw HTML Allowed

This component intentionally allows raw HTML injection in rendering callbacks and message content to give developers full control over content display. This is a conscious design choice, not a bug. If you display user-generated content, you must sanitize it yourself.

Overview

The DateRangePicker component uses innerHTML for rendering custom content in several callbacks and the showMessage() method. This provides maximum flexibility for creating rich, interactive content but requires developers to be aware of XSS (Cross-Site Scripting) implications when displaying untrusted data.

Callbacks & Methods Allowing HTML Injection

The following callbacks and methods output is rendered using innerHTML and will execute any HTML/JavaScript:

Callback/MethodUsed InRisk
showMessage(html)Message area in calendarHTML Injection
renderDayCallbackDay cell content (full replacement)HTML Injection
renderDayContentCallbackDay cell content (augmentation)HTML Injection
getDateMetadataCallback (badgeText)Badge text on datesHTML Injection
getDateMetadataCallback (dayTooltip)Tooltip on datesHTML Injection
formatSummaryCallbackSummary display (days/nights count)HTML Injection
getMonthHeaderCallbackMonth header textHTML Injection
getUnifiedHeaderCallbackUnified navigation headerHTML Injection
actionButtons[].labelCustom action button labelsHTML Injection
customStylesCallbackStyle tag injectionCSS Injection

Safe Callbacks

The following callbacks are safe - their output is escaped or used as data only:

CallbackUsageStatus
beforeDateSelectCallbackReturns action object (accept/reject/adjust)Safe
beforeMonthChangedCallbackReturns action object + metadataSafe
onSelectEvent handlerSafe
onChangeEvent handlerSafe
getDateMetadataCallback (isDisabled)Boolean checkSafe
getDateMetadataCallback (dayClass)CSS class names onlySafe
getDateMetadataCallback (badgeClass)CSS class names onlySafe

Why Allow Raw HTML?

Benefits

  • Full control over rendering
  • Rich content with images, icons, badges
  • Complex layouts in day cells
  • Custom pricing displays
  • Interactive message buttons
  • No limitations on creativity

Your Responsibility

  • Sanitize user-generated content
  • Validate data from external APIs
  • Use a sanitization library (DOMPurify, sanitize-html)
  • Escape special characters when needed
  • Review third-party data sources

Sanitization Examples

Using DOMPurify

Sanitizing with DOMPurify
 

Simple Text Escaping

Simple HTML Escaping
 

Safe Static Content

Trusted Data (No Sanitization)
 

When to Sanitize

Data SourceSanitization Required?Example
Your own database (controlled)Usually NoPricing data, availability, room counts
User input (forms, notes)Yes - AlwaysUser notes on dates, custom messages
External APIsYes - RecommendedThird-party booking data, weather info
URL parametersYes - AlwaysDate presets from URL, error messages
Static hardcoded valuesNoPrice labels, fixed tooltips, button text

Key Takeaways

  • This is intentional: Raw HTML support is a feature, not a vulnerability
  • You control the data: Only you know if your data is trusted
  • Sanitize at the boundary: Clean data before it enters rendering callbacks
  • Use established libraries: DOMPurify, sanitize-html, or your framework's built-in sanitizer
  • When in doubt, sanitize: It's better to over-sanitize than to expose an XSS vulnerability