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(connector-quorum/ethereum): strengthen contract parameter validation #2760

Closed
petermetz opened this issue Oct 10, 2023 · 3 comments · Fixed by #2854 or #3324
Closed

fix(connector-quorum/ethereum): strengthen contract parameter validation #2760

petermetz opened this issue Oct 10, 2023 · 3 comments · Fixed by #2854 or #3324
Assignees
Labels
good-first-issue Good for newcomers good-first-issue-400-expert Hacktoberfest Hacktoberfest participants are welcome to take a stab at issues marked with this label. P2 Priority 2: High Quorum Security Related to existing or potential security vulnerabilities
Milestone

Comments

@petermetz
Copy link
Contributor

petermetz commented Oct 10, 2023

Description

Static source code assessment has picked up a potential code injection vulnerability
in the code of the Quorum and Ethereum connectors where we pass in an array of
user-provided arguments to the EVM contract methods.

Web3JS already has validation on the number of arguments, but we could fortify
things on our end regardless by doing

  1. Additional type checking
  2. Ensuring that the number of arguments are the correct one (if we can obtain
    this information somehow from the ABI)

The report from which the above information was summarized

Risk Rating: High

Category: Injection

Description

The application's ‘invokeRawWeb3EthContract method’ receives and dynamically executes user-controlled code using invocationParams. This could enable an attacker to inject and run arbitrary code. The attacker can inject the executed code via user input, body, which is retrieved by the application in the handleRequest method.

Impact

An attacker could run arbitrary code on the application server host. Depending on the application’s OS permissions,these could include:

  • Database access, such as reading or modifying sensitive data.
  • File actions (read / create / modify / delete).
  • Changing the website
  • Open a network connection to the attacker’s server.
  • Decrypt secret data using the application's encryption keys.
  • Start and stop system services.
  • Complete server takeover.

Remediation Recommendation

  • The application should not compile, execute, or evaluate any untrusted code from any external source, including user input, uploaded files, or a database.
  • If it is absolutely necessary to include external data in dynamic execution, it is permissible to pass the data as parameters to the code, but do not execute user data directly.
  • If it is necessary to pass untrusted data to dynamic execution, enforce very strict data validation. For example, accept only integers between certain values.
  • Validate all input, regardless of source. Validation should be based on a whitelist: accept only data fitting a specified structure, rather than reject bad patterns. Parameters should be limited to an allowed character set, and non-validated input should be dropped. In addition to characters, check for:
    • Data type
    • Size
    • Range
    • Format
    • Expected values
  • If possible, always prefer to whitelist known and trusted input instead of comparing to a blacklist.
  • Configure the application to run using a restricted user account that has no unnecessary privileges.
  • If possible, isolate all dynamic execution to use a separate, dedicated user account that has privileges only for the specific operations and files used by dynamic execution, according to the Principle of Least Privilege.
  • Prefer passing user data to a pre-implemented script, e.g. in another isolated application, over dynamically executing user-controlled code.

Affected Files

Path
Line No

  • packages\cactus-plugin-ledger-connector-quorum\src\main\typescript\web-services\invoke-raw-web3eth-contract-v1-endpoint.ts.

    • Line number: 91
  • packages\cactus-plugin-ledger-connector-quorum\src\main\typescript\plugin-ledger-connector-quorum.ts

    • Line number: 904
  • packages\cactus-plugin-ledger-connector-ethereum\src\main\typescript\web-services\invoke-raw-web3eth-contract-v1-endpoint.ts.

    • Line number: 91
  • packages\cactus-plugin-ledger-connector-ethereum\src\main\typescript\plugin-ledger-connector-ethereum.ts.

    • Line number: 800

Snapshot of source code at the time of scan

image image

Source: APP PE Hyperledger Cacti v2.0.0 - Static Application Assessment Report.odt

cc: @takeutak @izuru0 @outSH

@petermetz petermetz added good-first-issue Good for newcomers good-first-issue-400-expert Hacktoberfest Hacktoberfest participants are welcome to take a stab at issues marked with this label. P2 Priority 2: High Quorum Security Related to existing or potential security vulnerabilities labels Oct 10, 2023
@petermetz petermetz added this to the vT.B.D milestone Oct 10, 2023
@outSH
Copy link
Contributor

outSH commented Oct 16, 2023

Good idea, we could use @ethersproject/abi to get function inputs from ABI and validate it's type - https://docs.ethers.org/v5/api/utils/abi/fragments/#FunctionFragment

@shivam-Purohit
Copy link
Contributor

hey @petermetz should I give it a try?

@petermetz
Copy link
Contributor Author

petermetz commented Oct 23, 2023

@shivam-Purohit Fine by me, yes! Thank you for your contribution in advance!

petermetz pushed a commit to petermetz/cacti that referenced this issue Jan 3, 2024
Peter's updates:
1. Made improvements to the test case verifying that the parameters with
incorrect types are indeed being rejected with useful error messaging
2. Added a new library (which I also had to re-publish with CJS exports)

Fixes hyperledger-cacti#2760

Signed-off-by: Shivam Purohit <[email protected]>
Signed-off-by: Peter Somogyvari <[email protected]>
petermetz pushed a commit to petermetz/cacti that referenced this issue Jan 9, 2024
Peter's updates:
1. Made improvements to the test case verifying that the parameters with
incorrect types are indeed being rejected with useful error messaging
2. Added a new library (which I also had to re-publish with CJS exports)

Fixes hyperledger-cacti#2760

Signed-off-by: Shivam Purohit <[email protected]>
Signed-off-by: Peter Somogyvari <[email protected]>
(cherry picked from commit 407bcf4)
petermetz pushed a commit to petermetz/cacti that referenced this issue Jan 24, 2024
Peter's updates:
1. Made improvements to the test case verifying that the parameters with
incorrect types are indeed being rejected with useful error messaging
2. Added a new library (which I also had to re-publish with CJS exports)

Fixes hyperledger-cacti#2760

Signed-off-by: Shivam Purohit <[email protected]>
Signed-off-by: Peter Somogyvari <[email protected]>
(cherry picked from commit 407bcf4)
petermetz pushed a commit to shivam-Purohit/cacti that referenced this issue Jan 24, 2024
Peter's updates:
1. Made improvements to the test case verifying that the parameters with
incorrect types are indeed being rejected with useful error messaging
2. Added a new library (which I also had to re-publish with CJS exports)

Fixes hyperledger-cacti#2760

Signed-off-by: Shivam Purohit <[email protected]>
Signed-off-by: Peter Somogyvari <[email protected]>
petermetz pushed a commit to petermetz/cacti that referenced this issue Jan 24, 2024
Peter's updates:
1. Made improvements to the test case verifying that the parameters with
incorrect types are indeed being rejected with useful error messaging
2. Added a new library (which I also had to re-publish with CJS exports)

Fixes hyperledger-cacti#2760

Signed-off-by: Shivam Purohit <[email protected]>
Signed-off-by: Peter Somogyvari <[email protected]>
(cherry picked from commit 407bcf4)
petermetz pushed a commit to petermetz/cacti that referenced this issue Jan 25, 2024
Peter's updates:
1. Made improvements to the test case verifying that the parameters with
incorrect types are indeed being rejected with useful error messaging
2. Added a new library (which I also had to re-publish with CJS exports)

Fixes hyperledger-cacti#2760

Signed-off-by: Shivam Purohit <[email protected]>
Signed-off-by: Peter Somogyvari <[email protected]>
(cherry picked from commit 407bcf4)
petermetz pushed a commit to shivam-Purohit/cacti that referenced this issue Jan 25, 2024
Peter's updates:
1. Made improvements to the test case verifying that the parameters with
incorrect types are indeed being rejected with useful error messaging
2. Added a new library (which I also had to re-publish with CJS exports)

Fixes hyperledger-cacti#2760

Signed-off-by: Shivam Purohit <[email protected]>
Signed-off-by: Peter Somogyvari <[email protected]>
petermetz pushed a commit that referenced this issue Jan 25, 2024
Peter's updates:
1. Made improvements to the test case verifying that the parameters with
incorrect types are indeed being rejected with useful error messaging
2. Added a new library (which I also had to re-publish with CJS exports)

Fixes #2760

Signed-off-by: Shivam Purohit <[email protected]>
Signed-off-by: Peter Somogyvari <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good-first-issue Good for newcomers good-first-issue-400-expert Hacktoberfest Hacktoberfest participants are welcome to take a stab at issues marked with this label. P2 Priority 2: High Quorum Security Related to existing or potential security vulnerabilities
Projects
None yet
3 participants