-
Notifications
You must be signed in to change notification settings - Fork 76
Enforce content-length validation on sender and size limits on payjoin-cli #808
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
base: master
Are you sure you want to change the base?
Conversation
6a23379 to
f2ab913
Compare
Pull Request Test Coverage Report for Build 17460319220Details
💛 - Coveralls |
144a8c3 to
6f409bb
Compare
d36cc26 to
95cb178
Compare
|
I have implemented the changes suggested. However, I had to introduce about two dependencies, which are:
as a result of that I attempted to update the lock files using the I want you to review what I have thus far, let me know if I am going in the right direction, as I find a solution to the error I am having. |
nothingmuch
left a comment
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.
This is looking great. Thank you!
The new dependencies are fine IMO, because they are already in our dependency chain if I'm not mistaken, and also because payjoin-cli can be more flexible about new dependencies than the payjoin crate.
The buffering code is very clear. I think a Vec<u8> can replace Bytes, since they are more or less the same on the inside, the main difference is Bytes support cheap clone(), which we don't need, for the cost of slightly more indirection.
Instead of duplicating it in the sender and receiver, a utility function can be added to payjoin-cli's app module.
Finally, as a nitpick, I find additional whitespace to be helpful when reading, but please try to commit such trivial changes in their own commits, that makes it easier to review commit by commit, github's files view uses lexicographical order for files and combines all the changes of all commits, both of which make it harder to spot important changes in between trivial ones.
20f8c0e to
0744af7
Compare
9c9313d to
c9fc215
Compare
|
I implemented the suggestions you gave, however, for the utility function, putting it in |
nothingmuch
left a comment
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.
I didn't quite understand your last comment about hyper & bytes, but i think the read_limited_body function is in the right place?
similar limiting for app/v2.rs can be added in a separate PR, with a fixed response size, and reusing this function, but moving it to the top level mod.rs should be straightforward (just making it pub(crate) and bringing in the necessary imports, namely hyper::body::Bytes)
anyway this is getting close, i only have some fairly small cleanup suggestions
|
Whenever this gets merged I suggest it get squashed rather than have all |
cc63c8d to
dcd8e28
Compare
08b6aa8 to
0467b86
Compare
|
Lint is failing with this: error[E0599]: no variant or associated item named `Parse` found for enum `core::send::error::InternalValidationError` in the current scope
--> payjoin/src/core/send/mod.rs:699:90
|
699 | let res_str = std::str::from_utf8(response).map_err(|_| InternalValidationError::Parse)?;
| ^^^^^ variant or associated item not found in `core::send::error::InternalValidationError`
|
::: payjoin/src/core/send/error.rs:94:1
|
94 | pub(crate) enum InternalValidationError {
| --------------------------------------- variant or associated item `Parse` not found for this enum
error[E0599]: no variant or associated item named `parse` found for enum `core::send::error::ResponseError` in the current scope
--> payjoin/src/core/send/mod.rs:700:75
|
700 | let proposal = Psbt::from_str(res_str).map_err(|_| ResponseError::parse(res_str))?;
| ^^^^^ variant or associated item not found in `core::send::error::ResponseError`
|
::: payjoin/src/core/send/error.rs:250:1
|
250 | pub enum ResponseError {
| ---------------------- variant or associated item `parse` not found for this enumI don't really know, I observed that the |
bdf0004 to
f4e816f
Compare
|
Resolved merge conflict. |
f4e816f to
1b23b8f
Compare
1b23b8f to
6a78579
Compare
This PR follows up on #770 and addresses the remaining improvements in comment. It implements stricter content-length validation and removes
MAX_CONTENT_LENGTHfrom the sender side, moving it topayjoin-cli.Summary of changes
Sender-side validation
MAX_CONTENT_LENGTHand validating that the actual body length matches theContent-Lengthheader.payjoin-clireceiver.collect(), to avoid unbounded memory allocations from a potentially malicious counterparty.payjoin-clisenderresponse.bytes()fromreqwest.Ref: #770
Closes: #756