tju-yxq opened a new issue, #1422:
URL: https://github.com/apache/rocketmq-dashboard/issues/1422

   ## Bug Report
   
   ### Before Creating the Bug Report
   
   - [x] I found a bug, not just asking a question, which should be created in 
[GitHub Discussions](https://github.com/apache/rocketmq/discussions).
   - [x] I have searched the [GitHub 
Issues](https://github.com/apache/rocketmq/issues) and [GitHub 
Discussions](https://github.com/apache/rocketmq/discussions) of this repository 
and believe that this is not a duplicate.
   - [x] I have confirmed that this bug belongs to the current repository, not 
other repositories of RocketMQ.
   
   ### Runtime platform environment
   
   OS: Ubuntu 20.04 / Any OS running RocketMQ Studio
   
   ### RocketMQ version
   
   branch: rocketmq-studio
   version: 5.3.2+
   Git commit id: f727341
   
   ### JDK Version
   
   OpenJDK 21
   
   ### Describe the Bug
   
   The SSRF guard in `SettingsService.isAllowedDataSourceHost()` blocks 
`"localhost"` by string comparison and blocks link-local addresses 
(`169.254.x.x`) and any-local addresses (`0.0.0.0`), but it does **not** check 
`isLoopbackAddress()`. This means `127.0.0.1` (and any `127.x.x.x` address) 
bypasses the guard, allowing an attacker to make the Studio server send HTTP 
requests to its own loopback interface.
   
   ```java
   private boolean isAllowedDataSourceHost(String host) {
       if (!StringUtils.hasText(host)) {
           return false;
       }
       String normalized = host.toLowerCase(Locale.ROOT);
       if ("localhost".equals(normalized)) {
           return false;  // blocks "localhost" string
       }
       try {
           InetAddress address = InetAddress.getByName(normalized);
           return !address.isAnyLocalAddress()      // blocks 0.0.0.0
                   && !address.isLinkLocalAddress(); // blocks 169.254.x.x
           // MISSING: !address.isLoopbackAddress()  ← 127.0.0.1 is NOT blocked!
       } catch (UnknownHostException exception) {
           return true;
       }
   }
   ```
   
   ### Impact
   
   An authenticated user (even a non-admin reader, since 
`/api/settings/datasources/test` is in `READER_POST_PATHS`) can test a data 
source URL pointing to `http://127.0.0.1:<port>/` and observe the response 
status and error messages. This allows:
   
   - **Port scanning** the Studio server's loopback interface by varying the 
port number.
   - **Accessing internal services** running on localhost (e.g., Spring 
Actuator endpoints at `http://127.0.0.1:8080/actuator/env`, database admin 
panels, etc.).
   - The response body is not returned, but the error message (`"Prometheus 
query failed"`, `"Connection refused"`, timeout vs. auth error) leaks whether a 
service is running on that port.
   
   ### Steps to Reproduce
   
   1. Open RocketMQ Studio settings.
   2. Go to Data Sources > Add.
   3. Enter URL: `http://127.0.0.1:8080/actuator/env` (or any internal service 
URL).
   4. Click "Test Connection".
   5. Observe: the test succeeds or returns a specific error (not "Data source 
URL must not point to a local or private address").
   6. Try with `http://localhost:8080/actuator/env` - this is correctly blocked.
   
   ### What Did You Expected to See?
   
   All loopback addresses (`127.0.0.1` through `127.255.255.255`) should be 
blocked, matching the existing `"localhost"` string filter.
   
   ### What Did You See Instead?
   
   `127.0.0.1` bypasses the SSRF guard because `isLoopbackAddress()` is not 
checked.
   
   ### Additional Context
   
   **Affected file**: 
`server/src/main/java/org/apache/rocketmq/studio/settings/SettingsService.java`,
 method `isAllowedDataSourceHost()` at approximately line 245.
   
   **Fix**: Add `!address.isLoopbackAddress()` to the return condition:
   
   ```java
   return !address.isAnyLocalAddress()
           && !address.isLinkLocalAddress()
           && !address.isLoopbackAddress();
   ```
   
   This is a one-line fix that closes the SSRF bypass.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to