Effect fixes ReDoS vulnerability in Schema.TemplateLiteral

  • Effect
  • ReDoS
  • regex

Ambiguous wildcards caused excessive backtracking on non-matching input

Version 3.22.1 uses a linear scan for affected templates

Issue affected versions up to 3.22.0

Effect fixed a denial-of-service vulnerability in Schema.TemplateLiteral in version 3.22.1. The flaw affected effect versions up to and including 3.22.0.

Applications decoding untrusted input with affected schemas could suffer long delays: a non-matching string of 5,000 characters could block the event loop for about 15 seconds. The risk applied to Schema.decodeUnknown, Schema.decodeUnknownSync and Schema.is, as well as HttpApi request payloads and @effect/rpc payloads built on those functions.

The vulnerability arose when a template contained at least two Schema.String spans. Their compiled regular expression used ambiguous wildcards, causing matching time to grow cubically with input length on non-matching input. The fix replaces the regular-expression match with a linear, left-to-right scan for templates whose spans are all Schema.String.