question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

After version 5.3.1 form arrays are mangled

See original GitHub issue

Upgrading to any version beyond 5.3.1 causes the req.body keys containing form arrays to become mangled into [object Object]. This affects not only in the custom() validator it also affects the value of req.body in the actual route handler for the request.

Example POST form data to express js endpoint:

name: some+name
alias: some+alias
param_data[id]: 12345
param_data[network_id]: 74634ae21

Console output using express-validator@5.3.1

req.body inside custom() {name: 'some name',
  alias: 'some alias',
  param_data: { id: '12345', network_id: '74634ae21' } }
req.body inside route { name: 'some name',
  alias: 'some alias',
  param_data: { id: '12345', network_id: '74634ae21' } }

Console output using express-validator@6.0.0 thru express-validator@6.2.0

req.body inside custom() { name: 'some name',
  alias: 'some alias',
  param_data: '[object Object]' }
req.body inside route { name: 'some name',
  alias: 'some alias',
  param_data: '[object Object]' }

Tested this in every version directly from 6.0.0 to 6.2.0 with the same results as above.

npm list --depth=0

proj@1.0.0 /path/to/proj
β”œβ”€β”€ @babel/cli@7.6.2
β”œβ”€β”€ @babel/core@7.6.2
β”œβ”€β”€ @babel/node@7.6.2
β”œβ”€β”€ @babel/plugin-transform-runtime@7.6.2
β”œβ”€β”€ @babel/polyfill@7.6.0
β”œβ”€β”€ @babel/preset-env@7.6.2
β”œβ”€β”€ @babel/register@7.6.2
β”œβ”€β”€ @babel/runtime@7.6.2
β”œβ”€β”€ @babel/runtime-corejs2@7.6.2
β”œβ”€β”€ aws-sdk@2.535.0
β”œβ”€β”€ babelify@9.0.0
β”œβ”€β”€ bluebird@3.5.5
β”œβ”€β”€ body-parser@1.19.0
β”œβ”€β”€ bootstrap@4.3.1
β”œβ”€β”€ browserify@16.5.0
β”œβ”€β”€ busboy@0.3.1
β”œβ”€β”€ compression@1.7.4
β”œβ”€β”€ config@1.31.0
β”œβ”€β”€ connect-flash@0.1.1
β”œβ”€β”€ connect-redis@3.4.2
β”œβ”€β”€ cookie-parser@1.4.4
β”œβ”€β”€ core-js@2.6.9
β”œβ”€β”€ csurf@1.10.0
β”œβ”€β”€ csv-express@1.2.2
β”œβ”€β”€ debug@2.6.9
β”œβ”€β”€ del@3.0.0
β”œβ”€β”€ do-wrapper@3.25.3
β”œβ”€β”€ es6-promise@4.2.8
β”œβ”€β”€ express@4.17.1
β”œβ”€β”€ express-session@1.16.2
β”œβ”€β”€ express-validator@5.3.1
β”œβ”€β”€ fast-csv@3.4.0
β”œβ”€β”€ handlebars@4.1.2
β”œβ”€β”€ intersection-observer@0.5.1
β”œβ”€β”€ jquery@3.4.1
β”œβ”€β”€ mdi@2.2.43
β”œβ”€β”€ moment@2.24.0
β”œβ”€β”€ mongoose@5.7.1
β”œβ”€β”€ mongoose-bcrypt@1.6.0
β”œβ”€β”€ mongoose-plugin-autoinc@1.1.9
β”œβ”€β”€ mongoose-unique-validator@2.0.3
β”œβ”€β”€ morgan@1.9.1
β”œβ”€β”€ nanoid@1.3.4
β”œβ”€β”€ node-sass@4.12.0
β”œβ”€β”€ node-schedule@1.3.2
β”œβ”€β”€ nopt@4.0.1
β”œβ”€β”€ passport@0.4.0
β”œβ”€β”€ passport-local@1.0.0
β”œβ”€β”€ permission@1.1.0
β”œβ”€β”€ popper.js@1.15.0
β”œβ”€β”€ saslprep@1.0.3
β”œβ”€β”€ serve-favicon@2.4.5
β”œβ”€β”€ tmp@0.0.33
β”œβ”€β”€ twig@0.10.3
β”œβ”€β”€ uglify-js@3.6.0
β”œβ”€β”€ underscore@1.9.1
β”œβ”€β”€ url-search-params@1.1.0
└── yargs@11.1.0

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
gustavohenkecommented, Oct 12, 2019

What happens is that before v6, non-string values wouldn’t be sanitised, which was a major security breach; thus, now they are converted to string before being sanitised.

If you expect it to be an object, you should validate it like so.

0reactions
gustavohenkecommented, Jan 18, 2020

Sorry for the delay – you should be able to use wildcards to do this. E.g. check('param_data.*').trim()

Read more comments on GitHub >

github_iconTop Results From Across the Web

useFieldArray resets form values after deleting item Β· Issue #892
Describe the bug All items appended to a field array are reset to the value given at append time when you delete an...
Read more >
ESS 5.3.1: Problem Determination Guide - IBM
This edition applies to version 5.3.1 of the Elastic Storage Server (ESS) ... array is reported in the long-form output of the mmlsrecoverygroup...
Read more >
Chapter 5. Loading, Linking, and Initializing
The class loader L can create an array of bytes representing C as the bytes of a ClassFile structure (Β§4.1); it then must...
Read more >
50+ array questions with solutions (easy, medium, hard)
50+ array interview questions, all with links to high-quality solutions, plus an arrays refresher and cheat-sheet.
Read more >
Version 5.3 Release Notes - WHMCS Documentation
1.1 Version 5.3.0 Beta 1; 1.2 Version 5.3.1 Beta 2; 1.3 Version 5.3.2 ... These steps can be used to upgrade from any...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found