apache / shardingsphere

Distributed SQL transaction & query engine for data sharding, scaling, encryption, and more - on any database.
Apache License 2.0
19.86k stars 6.73k forks source link

shardingsphere H2database snyk issue #30656

Closed xs996 closed 6 months ago

xs996 commented 6 months ago

Which version of ShardingSphere did you use?

shardingsphere-jdbc-core 5.4.1

Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?

ShardingSphere-JDBC

Expected behavior

snyk scan passed

Actual behavior

snyk reported a high issue about h2database

Reason analyze (If you can)

When we use h2database, snyk provides a high issue, and prompts that it cannot be repaired, The following is a detailed report:

_Affected versions of this package are vulnerable to Remote Code Execution (RCE). It provides a web console for managing the database, and by default it does not have a password set. The CREATE ALIAS function calls Java code, allowing an attacker to execute arbitrary Java code on projects running the h2 database.

Snyk report link: https://security.snyk.io/vuln/SNYK-JAVA-COMH2DATABASE-31685

Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.

snyk monitor

Example codes for reproduce this issue (such as a github link).

Snyk report link: https://security.snyk.io/vuln/SNYK-JAVA-COMH2DATABASE-31685

linghengqian commented 6 months ago
xs996 commented 6 months ago

I don't think this is a false positive from Snyk, here are the details I provided: image As you can see from the report, the current issue comes from shardingsphere-jdbc-core->shardingsphere-standalone-model-repository-jdbc->h2

xs996 commented 6 months ago

I found from the documentation that when I use Mode: Standalone I have to use H2 or MySQL to load my metadata,But we did not use the above database. Is there any way to remove h2database from source code? image

linghengqian commented 6 months ago
20001931 commented 6 months ago

Snyk reported https://security.snyk.io/vuln/SNYK-JAVA-COMH2DATABASE-2331071 please double check this high issue h2database import from shardingsphere 5.4.1 ![Uploading Screenshot 2024-03-27 104037.png…]()

To be honest,Metadata only keep in storage in H2 or MySQL ,that is not good idea,as you konw ,sometime we have not any choice,at this moment we just only use MSSQL ,but Snyk reported SNYK-JAVA-COMH2DATABASE-2331071 for Metadata in H2,Is it true that we have to build other MySQL for Metadata ,I think that is very funny!

xs996 commented 6 months ago
  • You can set the place to keep Metadata to other JDBC URL, whether it is MySQL or PostgreSQL.

If I don't use h2datbase and mysql to save my metadata, what should I do? Is there any corresponding documentation? Because I found in the documentation that Database Repository only supports H2 and Mysql

image

linghengqian commented 6 months ago
20001931 commented 6 months ago

thank your suggestion,let us try it

linghengqian commented 6 months ago
20001931 commented 6 months ago

I have other question for encrypt password for DB in shardingsphere 5.4.1 Could you provide suggestion for encrypt password for DB?

linghengqian commented 6 months ago
20001931 commented 6 months ago

I have checked shardingsphere 5.4.1,https://github.com/apache/shardingsphere/tree/5.4.1/infra/executor/src there is not any class org.apache.shardingsphere.infra.url.ShardingSphereURLLoader.

org.apache.shardingsphere shardingsphere-infra-url 5.4.2-SNAPSHOT

just need to encrypt a local YAML configuration file

linghengqian commented 6 months ago
20001931 commented 6 months ago

I have other question for decrypt password for DB in shardingsphere 5.4.1 As you konw i have encrypted password for DB in classpath yaml But where i intercept code shardingsphere read classpath yaml? url: jdbc:shardingsphere:classpath:sharding-dev.yaml?placeholder-type=system_props password: $${fixture.config.driver.password::} I konw can use URLArgumentLineRender to replace $${} But where i intercept code shardingsphere initiative read classpath yaml

linghengqian commented 6 months ago
20001931 commented 6 months ago

you did not get my point ,i konw to use ShardingSphereURLLoader reading YAML file,But i need to intercept code jdbcRepositoryProps.getValue(JDBCRepositoryPropertyKey.PASSWORD)) The password which i have encrypted in YAML file I need to decrypt this password and retuen the ShardingSphere dataSource you can not intercept the ShardingSphere dataSource if you just custom implementation ShardingSphereURLLoader May i konw how to intercept props in JDBCRepositoryProperties jdbcRepositoryProps = new JDBCRepositoryProperties(props); I need to change props before JDBCRepository init

linghengqian commented 6 months ago
20001931 commented 6 months ago

Could you share more detail? Where i can refer to code template? Do you mean use SPI org.apache.shardingsphere.mode.repository.standalone.StandalonePersistRepository point to custom implementation class?

linghengqian commented 6 months ago
20001931 commented 6 months ago

I got you point ,you mean i need change SPI org.apache.shardingsphere.mode.repository.standalone.StandalonePersistRepository to custom implementation class for example (JDBCRepositoryAli.class ) ,so i will control dataSource init ,that is right?

linghengqian commented 6 months ago

I got you point ,you mean i need change SPI org.apache.shardingsphere.mode.repository.standalone.StandalonePersistRepository to custom implementation class for example (JDBCRepositoryAli.class ) ,so i will control dataSource init ,that is right?

xs996 commented 6 months ago

Regarding database password encryption, I submitted a new Issue: https://github.com/apache/shardingsphere/issues/30896 I will close this issue

linghengqian commented 6 months ago
linghengqian commented 2 months ago

https://shardingsphere.apache.org/document/current/cn/user-manual/common-config/builtin-algorithm/metadata-repository/ has been updated by #32192. Now you can use MySQL Server, Embedded Derby, Derby Network Server, HyperSQL HSQL Server, HyperSQL HTTP Server, HyperSQL HTTP Servlet, (Embedded) HyperSQL to configure ShardingSphere Standalone Mode. So-called MySQL Server-compatible databases such as TiDB should also work.