Skip to content

Conversation

@jonasschnelli
Copy link
Contributor

Mentioned by SergioDemianLerner at f676c80#commitcomment-8996114

Make sure that we not send back raw request parameters.

@jgarzik
Copy link
Contributor

jgarzik commented Dec 16, 2014

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.

@jonasschnelli
Copy link
Contributor Author

Removing the variable from the error string would also be feasible method IMO.
Depends if we'd like to keep the "more information" in the error string.
But i agree with just have "invalid hash" instead of "invalid hash: /inputhash/", etc.

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 IsHex (eating cpu over rest with horrible path lengths, path_max is not specified in RFC as far as i know).

Somehow i have a feeling we should truncate and SanitizeString() all input parameters to prevent any possible upcoming damage.

@laanwj laanwj added the REST label Jan 8, 2015
@laanwj
Copy link
Member

laanwj commented Jan 26, 2015

+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.

@gavinandresen
Copy link
Contributor

I agree with @laanwj -- throw an error if given unsanitary input, don't try to fix it.
(but sanitize if input is logged as part of the error handling, of course)

@jonasschnelli
Copy link
Contributor Author

Agreed. I'll update the PR to detect unsanitary inputs and throw exception in such cases.

@jonasschnelli jonasschnelli force-pushed the 2014_12_rest_sanity branch 2 times, most recently from 1f71840 to 3ae0500 Compare March 12, 2015 13:00
@jonasschnelli
Copy link
Contributor Author

Updated.
Now it will detect unsafe inputs. Outputs still go though SanitizeString().

Copy link
Member

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.

@jonasschnelli
Copy link
Contributor Author

@laanwj: Right. Is was redundant.

I just updated the whole PR.
I did also remove SanitizeString() from error replies because we are now sure that hashes and amounts are correct formatted, etc.
How does it look now?

src/rest.cpp Outdated
Copy link

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?

Copy link
Contributor Author

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. :)

Copy link

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 & ;-).

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.
@laanwj
Copy link
Member

laanwj commented Mar 24, 2015

The redundant CheckRequestString check still seems to be there?

I'd personally have kept the SanitizeStrings on output just in case, as a kind of belt-and-suspenders, but no strong opinion there.

@jonasschnelli
Copy link
Contributor Author

@laanwj There is no more redundancy. CheckRequestString() will ensure input correctness, ParseHashStr() will no longer check for correctness of the hashstr to parse.
I removed SanitizeStrings because it was no longer possible to output a non hex hash or unlimited-non-digi-value.

@laanwj
Copy link
Member

laanwj commented Mar 24, 2015

ParseHashStr() will no longer check for correctness of the hashstr to parse.

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.

@jonasschnelli
Copy link
Contributor Author

I'm also not happy with the solution. Let me try to optimize and shuffle around some things.

@laanwj laanwj closed this Jul 10, 2015
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants