Skip to main content
WireMock Cloud provides a naughtyString helper that returns strings from the Big List of Naughty Strings (BLNS). The list contains strings that commonly cause problems in software, such as SQL injection, right-to-left text, zero-width characters, emoji and Zalgo text. Using the helper in a stub means every client test that calls it exercises these cases without any extra setup.
These are real payloads. The XSS, SQL injection and command injection strings reach whatever consumes the mock, including logs, databases and browsers. That is the point, but only point clients at these stubs in environments where that is safe.
The list is built in to WireMock Cloud, so there is nothing to install or download. The stub needs response templating enabled, as with any other helper.

Choosing a string

By default the helper picks a random string from the whole list. The category and index parameters narrow the choice.
With neither parameter, the helper picks at random from all 516 strings.

Errors

Bad input renders an error string in the response, in the same way as WireMock’s built-in helpers:
  • An unknown category gives [ERROR: Unknown BLNS category 'x'. Known: reserved-strings, …].
  • An index outside the range gives [ERROR: BLNS index 600 is out of range 0-515]. The index does not wrap around, so a typo can’t quietly return the wrong string.

Browsing the list

To see every string in every category, with the index you would use to select it, open the hosted mock API at blns.wiremockapi.cloud/naughty/strings. It returns the whole list as plain text, grouped by category, with each category’s indexes starting at 0. You can also build your own version. To see which string you get at each index, use a stub that prints a category with the range and each helpers. This one prints every string in sql-injection:
Which gives this response:
The upper bound of range is inclusive, so use the category’s string count from the table below minus one. A bound that is too high is harmless: the extra lines show the out-of-range error, which is a handy way to confirm where a category ends. Remove the category parameter and use range 0 515 to print the whole list. The output is long, because it includes the 236 script injection strings. Some strings contain characters that are invisible or render oddly, such as zero-width characters. Their indexes can look empty or identical in the response, so treat the output as a guide to which index you want rather than a faithful view of every byte.

JSON bodies

WireMock Cloud does not escape helper output, so a naughty string placed directly into JSON will often break it. Quotes, backslashes and control characters are the usual culprits. Wrap the helper in the toJson helper, which adds the surrounding quotes and escapes the value. Use triple braces and leave the value unquoted:
Every string in the list comes back from this pattern as valid JSON that parses to the original string. Use this in the response body, not jsonBody. Inside a jsonBody string value ("name": "{{{toJson …}}}") the quotes are doubled up and the result is invalid JSON.

Categories

Use either the category name or its slug as the category parameter.

Attribution

The Big List of Naughty Strings is © Max Woolf and licensed under the MIT licence.