Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getLastErrors is not thread safe #189

Open
kevinburke opened this issue Aug 3, 2017 · 0 comments
Open

getLastErrors is not thread safe #189

kevinburke opened this issue Aug 3, 2017 · 0 comments

Comments

@kevinburke
Copy link

kevinburke commented Aug 3, 2017

If I am sharing a validator instance across multiple Node workers running on different CPU processes, getLastErrors is not a safe API. Consider the following sequence of events:

  • Thread 1 calls validator.validate and stores a value on lastReport
  • Thread 2 calls validator.validate and stores a value on lastReport
  • Thread 1 calls getLastErrors and retrieves the error from Thread 2.

This may expose private data from the request in Thread 2 to Thread 1, so this is also a security risk.

In my experience running Node with e.g. cluster, https://nodejs.org/api/cluster.html, or https://github.com/hunterloftis/throng is pretty common, and it wouldn't be too odd to see a single validator shared by each of these threads.

A better API may be to have validate throw the value currently being stored in lastReport (if any) so the user performing the validation can catch it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants