Repository navigation
rpcutils+rpcserver: reject unknown rpc asset type and sort values #2397
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: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -801,9 +801,14 @@ func (r *RPCServer) MintAsset(ctx context.Context, | |
| "and group internal key descriptor") | ||
| } | ||
|
|
||
| assetType, err := rpcutils.UnmarshalAssetType(req.Asset.AssetType) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| seedling := &tapgarden.Seedling{ | ||
| AssetVersion: assetVersion, | ||
| AssetType: asset.Type(req.Asset.AssetType), | ||
| AssetType: assetType, | ||
| AssetName: req.Asset.Name, | ||
| Amount: req.Asset.Amount, | ||
| EnableEmission: req.Asset.NewGroupedAsset, | ||
|
|
@@ -6888,6 +6893,41 @@ func unmarshalUniSortDirection( | |
| } | ||
| } | ||
|
|
||
| // unmarshalUniSyncStatsSort parses the RPC asset query sort field into | ||
| // the native sync stats sort counterpart. | ||
| func unmarshalUniSyncStatsSort( | ||
| rpcSort unirpc.AssetQuerySort) (universe.SyncStatsSort, error) { | ||
|
|
||
| switch rpcSort { | ||
| case unirpc.AssetQuerySort_SORT_BY_NONE: | ||
| return universe.SortByNone, nil | ||
|
|
||
| case unirpc.AssetQuerySort_SORT_BY_ASSET_NAME: | ||
| return universe.SortByAssetName, nil | ||
|
|
||
| case unirpc.AssetQuerySort_SORT_BY_ASSET_ID: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use rows whose ID and type orders differ to test both sort modes through |
||
| return universe.SortByAssetID, nil | ||
|
|
||
| case unirpc.AssetQuerySort_SORT_BY_ASSET_TYPE: | ||
| return universe.SortByAssetType, nil | ||
|
|
||
| case unirpc.AssetQuerySort_SORT_BY_TOTAL_SYNCS: | ||
| return universe.SortByTotalSyncs, nil | ||
|
|
||
| case unirpc.AssetQuerySort_SORT_BY_TOTAL_PROOFS: | ||
| return universe.SortByTotalProofs, nil | ||
|
|
||
| case unirpc.AssetQuerySort_SORT_BY_GENESIS_HEIGHT: | ||
| return universe.SortByGenesisHeight, nil | ||
|
|
||
| case unirpc.AssetQuerySort_SORT_BY_TOTAL_SUPPLY: | ||
| return universe.SortByTotalSupply, nil | ||
|
|
||
| default: | ||
| return 0, fmt.Errorf("unknown asset query sort: %v", rpcSort) | ||
| } | ||
| } | ||
|
|
||
| // validatePage validates the pagination parameters for universe | ||
| // queries. | ||
| func validatePage(offset, limit int32) error { | ||
|
|
@@ -9016,6 +9056,11 @@ func (r *RPCServer) QueryAssetStats(ctx context.Context, | |
| limit = universe.RequestPageSize | ||
| } | ||
|
|
||
| sortBy, err := unmarshalUniSyncStatsSort(req.SortBy) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An unknown |
||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| assetStats, err := r.cfg.UniverseStats.QuerySyncStats( | ||
| ctx, universe.SyncStatsQuery{ | ||
| AssetNameFilter: req.AssetNameFilter, | ||
|
|
@@ -9034,7 +9079,7 @@ func (r *RPCServer) QueryAssetStats(ctx context.Context, | |
| AssetIDFilter: fn.ToArray[asset.ID]( | ||
| req.AssetIdFilter, | ||
| ), | ||
| SortBy: universe.SyncStatsSort(req.SortBy), | ||
| SortBy: sortBy, | ||
| SortDirection: unmarshalUniSortDirection(req.Direction), | ||
| Offset: int(req.Offset), | ||
| Limit: int(limit + 1), | ||
|
|
||
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.
Exercise the caller paths too. Assert that
MintAssetrejects an unknown type before queueing and that group key request decoding rejects an unknown anchor asset type.