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.
Choosing a string
By default the helper picks a random string from the whole list. Thecategory 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
indexoutside 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 therange and each helpers. This one prints every string in sql-injection:
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 thetoJson helper, which adds the surrounding quotes and escapes the value.
Use triple braces and leave the value unquoted:
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 thecategory parameter.