Compare commits

...
Author SHA1 Message Date
aias00 64dd8a5aeb Merge branch 'master' into fix/alert-53 2025-05-18 17:03:43 +08:00
Calvin d140165b41 Merge branch 'master' into fix/alert-53 2025-05-18 13:48:38 +08:00
liuhy 6b9fbe8206 fix alert 2025-05-17 15:07:48 +08:00
aias00andCopilot Autofix powered by AI 89e4b8911d Potential fix for code scanning alert no. 53: Server-side request forgery
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: aias00 <liuhongyu@apache.org>
2025-05-17 14:32:38 +08:00
2 changed files with 16 additions and 3 deletions
@@ -17,8 +17,6 @@
package org.apache.hertzbeat.warehouse.controller;
import static org.apache.hertzbeat.common.constants.CommonConstants.FAIL_CODE;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
@@ -33,6 +31,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import static org.apache.hertzbeat.common.constants.CommonConstants.FAIL_CODE;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
/**
* Indicator data query interface
*/
@@ -99,7 +100,9 @@ public class MetricsDataController {
String app = names[0];
String metrics = names[1];
String metric = names[2];
MetricsHistoryData historyData = metricsDataService.getMetricHistoryData(monitorId, app, metrics, metric, label, history, interval);
return ResponseEntity.ok(Message.success(historyData));
}
}
@@ -361,7 +361,12 @@ public class VictoriaMetricsDataStorage extends AbstractHistoryDataStorage {
+ SignConstants.BLANK + encodedAuth);
}
HttpEntity<Void> httpEntity = new HttpEntity<>(headers);
URI uri = UriComponentsBuilder.fromHttpUrl(victoriaMetricsProp.url() + QUERY_RANGE_PATH)
// Ensure victoriaMetricsProp.url() is a trusted base URL
String baseUrl = victoriaMetricsProp.url();
if (!isTrustedBaseUrl(baseUrl)) {
throw new IllegalStateException("Untrusted base URL: " + baseUrl);
}
URI uri = UriComponentsBuilder.fromHttpUrl(baseUrl + QUERY_RANGE_PATH)
.queryParam(URLEncoder.encode("query", StandardCharsets.UTF_8), URLEncoder.encode("{" + timeSeriesSelector + "}", StandardCharsets.UTF_8))
.queryParam("step", "4h")
.queryParam("start", startTime)
@@ -532,4 +537,9 @@ public class VictoriaMetricsDataStorage extends AbstractHistoryDataStorage {
*/
private Long[] timestamps;
}
private boolean isTrustedBaseUrl(String url) {
// Define a trusted base URL
return url.equals("http://trusted-victoriametrics-server.com");
}
}