Skip to main content

Security

A message is whatever its sender put in it, so the library treats every field as untrusted:

  • Links open only with a safe scheme. Text links, markdown links and link previews open with http, https, mailto, tel or sms; a message's media and files with http, https, file or content. Anything else (javascript:, intent:, data:, an app's custom scheme) does nothing and logs the scheme alone. When you handle a press yourself (messageTextProps.onPress, onPressLinkPreview, a matcher's onPress), check the URL with the exported isSafeLinkUrl / isSafeMediaUrl before opening it.
  • A malformed message cannot take the chat down. Chat and ChatList check each message and chat as it arrives: a field of the wrong type is dropped, and a message without a string or number _id, or with an _id already used, is left out. Well-formed messages pass through untouched, as the same objects. A row that still throws while rendering, for example in a render prop of yours, hides itself and the rest of the chat stays.
  • Long messages cannot freeze it. Link detection scans a long text in bounded pieces and skips any run of more than 4096 characters with no whitespace, so its cost grows in step with the text.
  • Nothing a sender wrote reaches the device log. The library's warnings name ids, field names and URL schemes, never message text or URLs.
  • File names cannot disguise their type. Characters that reorder text (right-to-left overrides) are removed from a file's displayed name, and its icon shows the real extension.

What stays with your app: limit message size and validate messages on your server, and fetch link previews there too. A fetchLinkPreview that loads the page on the device tells every linked site the reader's IP address.