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

[cms] Add passthroughs for proposals requests #1171

Merged
merged 8 commits into from
Jun 17, 2020

Conversation

alexlyp
Copy link
Member

@alexlyp alexlyp commented Apr 16, 2020

This allows us to request https://cms.decred.org/api/v1/proposals/tokeninventory and https://cms.decred.org/api/v1/proposals/batch to avoid a cross site request that causes security issues. This simple passes that request through via the API to the relevant proposals site (mainnet/testnet).

@alexlyp alexlyp changed the title http: Add header to allow requests from cms.decred.org [cms] Add passthrough for TokenInventory requests Apr 16, 2020
}

data, _ := ioutil.ReadAll(resp.Body)
util.RespondRaw(w, http.StatusOK, data)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
util.RespondRaw(w, http.StatusOK, data)
resp.Body.Close()
util.RespondRaw(w, http.StatusOK, data)

resp, err := http.Get(route)
if err != nil {
RespondWithError(w, r, 0,
"SOME ERROR", err)
Copy link
Member

Choose a reason for hiding this comment

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

we would want to handle this properly

@@ -865,6 +887,9 @@ func (p *politeiawww) setCMSWWWRoutes() {
p.addRoute(http.MethodGet, cms.APIRoute,
cms.RouteProposalOwner, p.handleProposalOwner,
permissionLogin)
p.addRoute(http.MethodGet, cms.APIRoute,
www.RouteTokenInventory, p.handlePassThroughTokenInventory,
permissionPublic)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe set this to permissionLogin . This would avoid the public hitting this heavy end point by mistake.

Suggested change
permissionPublic)
permissionLogin)

@alexlyp alexlyp changed the title [cms] Add passthrough for TokenInventory requests [cms] Add passthroughs for proposals requests Apr 21, 2020
Copy link
Member

@lukebp lukebp left a comment

Choose a reason for hiding this comment

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

ACK

@marcopeereboom will want to look at this.

@alexlyp alexlyp requested a review from marcopeereboom May 5, 2020 20:44
return
}
defer func() {
resp.Body.Close()
Copy link
Member

Choose a reason for hiding this comment

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

Closing here.

}()

data, _ := ioutil.ReadAll(resp.Body)
resp.Body.Close()
Copy link
Member

Choose a reason for hiding this comment

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

And here.


// VerifyProposal verifies a proposal's merkle root, author signature, and
// censorship record.
func VerifyProposal(p v1.ProposalRecord, serverPubKey string) error {
Copy link
Member

Choose a reason for hiding this comment

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

We are going to need unit tests for this function where we test all failure modes.

Copy link
Member Author

Choose a reason for hiding this comment

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

This was an existing unexported func in piwww. Where do you want these tests? I'm not seeing any in piwww.

}

data, _ := ioutil.ReadAll(resp.Body)
resp.Body.Close()
Copy link
Member

Choose a reason for hiding this comment

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

I'd make this a defer right after the GET.

@@ -30,6 +31,19 @@ func RespondWithJSON(w http.ResponseWriter, code int, payload interface{}) {
w.Write(response)
}

func RespondRaw(w http.ResponseWriter, code int, payload []byte) {
Copy link
Member

Choose a reason for hiding this comment

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

This should be shared with the various CLI tools. So that we only have to change it once and not multiple times.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's exported within the util package, so it should be able to be used anywhere that it's necessary. What other tools should use it?

@alexlyp alexlyp merged commit 63d6af4 into decred:master Jun 17, 2020
@alexlyp alexlyp deleted the ayp_headers branch June 17, 2020 17:27
vibros68 pushed a commit to vibros68/politeia that referenced this pull request Aug 17, 2021
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