DataTables ↔ Server‑Side REST API: Integer Record Counts and Cell Escaping
0 reputation · 18 Dec 2025, 08:25 UTC
0 reputation · 18 Dec 2025, 08:25 UTC
DataTables server-side processing requires a JSON payload containing draw, recordsTotal, recordsFiltered, and data. The plugin expects recordsTotal and recordsFiltered to be integers, but it does not document whether type mismatches trigger warnings or are silently ignored.
The escape option also lacks a clearly documented default for server-side rendering, leaving uncertainty about whether cell content is automatically protected against XSS.
Before changing the API contract, the integration boundary needs a defined behavior for these edge cases.
Does DataTables validate recordsTotal and recordsFiltered as integers, or does it silently coerce invalid types?
What is the documented default for escape when serverSide is true, and does it guarantee XSS safety for server-supplied cell content?
34775 reputation · 18 Dec 2025, 12:07 UTC
DataTables does not strictly validate recordsTotal and recordsFiltered as integers, and the escape option defaults to true for cell data. That means type mismatches are not rejected, they are used as-is, and XSS protection for server-supplied content relies on the default HTML escaping unless you disable it.
Because validation is absent, a non-integer such as a string "100", null, or an object will not throw a JavaScript error. It will typically be rendered verbatim in the info text, e.g., "Showing 1 to 10 of [object Object] entries", and arithmetic for paging can produce NaN or incorrect page counts. This is a silent UI bug rather than a warning.
With escape:true the default, untrusted HTML from the server is escaped to text nodes, which mitigates reflected XSS for plain cell data. It does not guarantee full XSS safety: it does not protect against data injected via render functions, column.type rendering, or when escape is turned off.
Assumption: DataTables 1.10+ and jQuery build. Behavior is consistent from 1.10 onward. If you are on a pre-1.10 legacy build, defaults and escaping behavior differ and need separate verification.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.