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

Verify Stargate Queries handles properly #776

Merged
merged 2 commits into from
Mar 9, 2022
Merged

Conversation

ethanfrey
Copy link
Member

Closes #762

@ethanfrey ethanfrey requested a review from alpe as a code owner March 7, 2022 21:47
@codecov
Copy link

codecov bot commented Mar 7, 2022

Codecov Report

Merging #776 (4638213) into master (f35a13f) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #776      +/-   ##
==========================================
+ Coverage   58.61%   58.63%   +0.02%     
==========================================
  Files          49       49              
  Lines        5835     5838       +3     
==========================================
+ Hits         3420     3423       +3     
  Misses       2165     2165              
  Partials      250      250              
Impacted Files Coverage Δ
x/wasm/keeper/query_plugins.go 79.93% <100.00%> (+0.19%) ⬆️

x/wasm/keeper/query_plugins.go Outdated Show resolved Hide resolved
x/wasm/keeper/query_plugins.go Outdated Show resolved Hide resolved
Copy link
Contributor

@alpe alpe left a comment

Choose a reason for hiding this comment

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

This solves the issue already.
@webmaster128 had some good points that would improve the solution. I added some comments for bonus points.

func StargateQuerier(queryRouter GRPCQueryRouter) func(ctx sdk.Context, request *wasmvmtypes.StargateQuery) ([]byte, error) {
return func(ctx sdk.Context, msg *wasmvmtypes.StargateQuery) ([]byte, error) {
for _, b := range queryDenyList {
if strings.Contains(msg.Path, b) {
return nil, wasmvmtypes.UnsupportedRequest{Kind: fmt.Sprintf("'%s' path is not allowed from the contract", msg.Path)}
Copy link
Contributor

Choose a reason for hiding this comment

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

I want to be more sensible to not return user input in errors. Would 'path is not allowed from the contract' be good enough? The caller knows the path already.

Copy link
Member Author

Choose a reason for hiding this comment

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

I updated this. The caller (user) will not know by default, as this is called from a contract. But I did redact.

Also, 3 lines lower we already had this code:
return nil, wasmvmtypes.UnsupportedRequest{Kind: fmt.Sprintf("No route to query '%s'", msg.Path)}

Which I wrote March 2021. Should we change that as well?

x/wasm/keeper/reflect_test.go Show resolved Hide resolved
@ethanfrey
Copy link
Member Author

Addressed comments. Waiting for CI

@ethanfrey ethanfrey merged commit c1a72f7 into master Mar 9, 2022
@ethanfrey ethanfrey deleted the limit-stargate-querier branch March 9, 2022 11:26
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.

Better tests for StargateQuery
3 participants