Skip to content

rpc: disallow PUT and DELETE on HTTP RPC (#15493)#15501

Merged
fjl merged 3 commits into
ethereum:masterfrom
armaniferrante:15493
Nov 17, 2017
Merged

rpc: disallow PUT and DELETE on HTTP RPC (#15493)#15501
fjl merged 3 commits into
ethereum:masterfrom
armaniferrante:15493

Conversation

@armaniferrante
Copy link
Copy Markdown
Contributor

@armaniferrante armaniferrante commented Nov 16, 2017

Addresses #15493 .

Extracted HTTP request checks into a separate method.

If more checks like this are added in the future, it might be nice to abstract this even more, perhaps having some notion of a "rule" with a validation function (though this is probably overkill for now).

Also added some basic tests to cover the changes.

Copy link
Copy Markdown
Contributor

@holiman holiman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@fjl fjl merged commit c5b8569 into ethereum:master Nov 17, 2017
Copy link
Copy Markdown
Member

@karalabe karalabe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, will do a followup pr.

Comment thread rpc/http_test.go
httpErrorResponseTest(t, "POST", contentType, "", 0)
}

func httpErrorResponseTest(t *testing.T,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please call this testHTTPErrorResponse. Lower case won't be executed and it's usually the convention.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a helper called by all the other tests.

Comment thread rpc/http_test.go
@@ -0,0 +1,40 @@
package rpc
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the LGPL copyright header that we have on each of our source files.

Comment thread rpc/http.go
srv.ServeSingleRequest(codec, OptionMethodInvocation)
}

// Returns a non-zero response code and error message if the request is invalid.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method docs in Go start with the name of the method. ie.

// httpErrorResponse returns a non-zero response code and error message if the request is invalid.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also rather call it validateRequest, to make it clearer what it does.

Comment thread rpc/http.go
http.Error(w,
"invalid content type, only application/json is supported",
http.StatusUnsupportedMediaType)
if responseCode, errorMessage := httpErrorResponse(r); responseCode != 0 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpicking, but perhaps use shorted variable names?

responseCode -> code
errorMessage -> err

Comment thread rpc/http.go
}

// Returns a non-zero response code and error message if the request is invalid.
func httpErrorResponse(r *http.Request) (int, string) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of returning (int, string), please return (int, error). That makes it a lot cleaner imho, since you don't need to check for 0 equality outside (which is arbitrary), rather can do a clean error check which is the standard in Go.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants