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

Fix case sensitive query parameters #8852

Conversation

jascks
Copy link
Contributor

@jascks jascks commented Jul 22, 2024

Description:

Some rest api endpoints return 500 with order=ASC / order=DESC, examples:

  • https://mainnet-public.mirrornode.hedera.com/api/v1/contracts/results/logs?order=ASC
  • https://mainnet-public.mirrornode.hedera.com/api/v1/accounts/0.0.1274288/nfts?limit=100&order=ASC

The transactions REST API misinterprets query filter result=SUCCESS to look for transactions with response code not equal to 22. The issue is only all lower case success is interpreted as response code equal to 22. On top of the inverted interpretation, this may also cause query timeout, e.g., when combined with account.id for which there's very few failed transactions.

This PR, in the requestHander.js middleware Express query parser, ensures the query parameter values to selected parameters (currently just order and result) are forced to lowercase before the request is routed to the request handler code.

Related issue(s):

Fixes #8790
Fixes #8801

Notes for reviewer:

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

…rameter values.

Introduce small framework to extend to other query parameter keys as required.

Signed-off-by: Jeff Schmidt <jeffrey.schmidt@swirldslabs.com>
@jascks jascks linked an issue Jul 22, 2024 that may be closed by this pull request
@jascks jascks self-assigned this Jul 22, 2024
@jascks jascks added bug Type: Something isn't working rest Area: REST API labels Jul 22, 2024
@jascks jascks modified the milestones: 0.110.0, 0.111.0 Jul 22, 2024
@jascks jascks requested review from a team and jnels124 and removed request for a team July 22, 2024 21:11
Copy link

codecov bot commented Jul 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.19%. Comparing base (3b4ed0d) to head (d4e81e1).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #8852   +/-   ##
=========================================
  Coverage     92.19%   92.19%           
- Complexity     7597     7598    +1     
=========================================
  Files           925      925           
  Lines         30407    30427   +20     
  Branches       3694     3706   +12     
=========================================
+ Hits          28033    28053   +20     
  Misses         1548     1548           
  Partials        826      826           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mgoelswirlds mgoelswirlds modified the milestones: 0.111.0, 0.110.0 Jul 23, 2024
Signed-off-by: Xin Li <xin@swirldslabs.com>
Copy link
Member

@steven-sheehy steven-sheehy left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@mgoelswirlds mgoelswirlds left a comment

Choose a reason for hiding this comment

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

LGTM

@steven-sheehy steven-sheehy changed the title Some REST API endpoints are problematic when query parameter values are not lowercase Fix case sensitive query parameters Jul 23, 2024
Copy link

sonarcloud bot commented Jul 23, 2024

@steven-sheehy steven-sheehy merged commit 2db2621 into main Jul 23, 2024
29 checks passed
@steven-sheehy steven-sheehy deleted the 8790-some-rest-api-endpoints-return-500-with-order=asc-order=desc branch July 23, 2024 18:22
bilyana-gospodinova pushed a commit that referenced this pull request Jul 24, 2024
Some rest api endpoints return 500 with `order=ASC` /  `order=DESC`, examples:

- `https://mainnet-public.mirrornode.hedera.com/api/v1/contracts/results/logs?order=ASC`
- `https://mainnet-public.mirrornode.hedera.com/api/v1/accounts/0.0.1274288/nfts?limit=100&order=ASC`

The transactions REST API misinterprets query filter `result=SUCCESS` to look for transactions with response code not equal to 22. The issue is only all lower case `success` is interpreted as response code equal to 22. On top of the inverted interpretation, this may also cause query timeout, e.g., when combined with `account.id` for which there's very few failed transactions.

This PR, in the `requestHander.js` middleware Express query parser, ensures the query parameter values to selected parameters (currently just `order` and `result`) are forced to lowercase before the request is routed to the request handler code.
---------

Signed-off-by: Jeff Schmidt <jeffrey.schmidt@swirldslabs.com>
Signed-off-by: Xin Li <xin@swirldslabs.com>
Co-authored-by: Xin Li <xin@swirldslabs.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Type: Something isn't working rest Area: REST API
Projects
None yet
4 participants