Presto JDBC Server-Side Request Forgery by redirect
Date: 2023-10
Affected: maven/com.facebook.presto:presto-jdbc
Attack vector: ssrf
Category: vulnerability-disclosure
Severity: High
CWE: CWE-918
CVSS: 7.6 (CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:L/A:L)

### Summary Presto 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. ### Details Presto 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. For 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. The relevant code is in file path `/presto-client/src/main/java/com/facebook/presto/client/StatementClientV1.java` and function `StatementClientV1` . The flowchart is as follows: <img src="https://s2.loli.net/2023/09/18/AhiHNL5neuYIK4X.png" alt="trino_jdbc_ssrf_1.png" style="zoom:50%;" /> ### PoC Running an HTTP service to route POST /v1/statement redirect to the intranet. For example, using these Python code: ```python from flask import Flask, redirect app = Flask(__name__) @app.route('/v1/statement', methods=['POST']) def redirect_to_interal_server(): return redirect('http://127.0.0.1:8888', code=302) if __name__ == '__main__':


Mitigations:

Architectural layers (MAESTRO):