-
Notifications
You must be signed in to change notification settings - Fork 38.7k
[REST] basic input/output sanity check #5492
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
Conversation
|
What about rethinking the logic a bit? This is only needed for error responses that echo back to the client a piece of information it already knows. It seems like each case could be simplified by removing the variable portion of each error string. |
|
Removing the variable from the error string would also be feasible method IMO. On the other hand it could be handy and save(r) for upcoming implementations to make sure input parameters gets a minimalistic check. In the current implementation there is a minimalistic very tiny risk of exploiting Somehow i have a feeling we should truncate and |
|
+1 for better input validation. However I don't like the approach of using sanitize for input strings. It should either accept the input as-is or reject it and throw an error immediately. Don't try to proceed at all using 'sanitized' input. Using sanitizestring for logged messages makes sense. |
|
I agree with @laanwj -- throw an error if given unsanitary input, don't try to fix it. |
|
Agreed. I'll update the PR to detect unsanitary inputs and throw exception in such cases. |
1f71840 to
3ae0500
Compare
|
Updated. |
Mentioned by SergioDemianLerner at bitcoin@f676c80#commitcomment-8996114
3ae0500 to
367790d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this pre-check redundant? e.g., ParseHashStr will already fail on invalid hashes. Or should, at least.
|
@laanwj: Right. Is was redundant. I just updated the whole PR. |
src/rest.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you not using const std::string& inputString?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right.
The rest.cpp class was introduced with using namespace std; which is somehow inconsistent with other classes/files. This PR just follows the current rest.cpp implementation code style. But i'm pretty sure someone will open a PR to fix this. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The important part wasn't the std:: it was the & ;-).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha. Yes. Right. will change that to pass-by-ref.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you not using const std::string& inputString?
Fixed.
- removed SanitizeString() because we now make sure that input parameters are correct. - more precise parameter check including more details error string.
114c13c to
d5b73e1
Compare
|
The redundant I'd personally have kept the SanitizeStrings on output just in case, as a kind of belt-and-suspenders, but no strong opinion there. |
|
@laanwj There is no more redundancy. |
To me it seems that was an excellent place to do the check. Where possible, combining checking input and parsing makes sense, as it reduces the scope for error. |
|
I'm also not happy with the solution. Let me try to optimize and shuffle around some things. |
Mentioned by SergioDemianLerner at f676c80#commitcomment-8996114
Make sure that we not send back raw request parameters.