Skip to main content

What it flags

A synchronous Node filesystem read decodes a caller-selected file as UTF-8. The rule follows an unchanged string path parameter from an exported function or public method of an exported class. It recognizes an explicit UTF-8 read or a buffer decoded with toString, followed by replace or replaceAll and a synchronous write to the same path. Node’s permissive decoding can replace invalid UTF-8 with U+FFFD, which changes bytes outside the intended edit. The finding appears with --include-contextual.

How to review or fix

Check the application’s input encoding contract. If invalid UTF-8 must be rejected, validate with a fatal decoder before writing and preserve any required byte order mark. If other encodings are supported, decode and encode using the file’s known encoding.