Skip to content

Commit a427f91

Browse files
committed
fix:codeql scan Security issue
1 parent 9e2eb51 commit a427f91

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

‎base/src/main/java/com/tinyengine/it/service/app/impl/v1/AiChatV1ServiceImpl.java‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ public Object chatCompletion(ChatRequest request) throws Exception {
131131
String encryptApiKey =
132132
request.getApiKey() != null ? request.getApiKey() : config.getApiKey();
133133
String apiKey = getApiKey(encryptApiKey);
134-
// The network target is controlled by server-side configuration, never request input.
135-
String normalizedUrl = normalizeApiUrl();
134+
String normalizedUrl = normalizeApiUrl(request.getBaseUrl());
136135

137136
// 对最终请求 URL 做安全校验(在 normalize 之后,确保校验的是真正发出的地址)
138137
URI requestUri = validateFinalUrl(normalizedUrl);
@@ -169,8 +168,12 @@ public String getToken(String apiKey) throws GeneralSecurityException {
169168
*
170169
* @return normalized API URL
171170
*/
172-
private String normalizeApiUrl() {
173-
final String normalizedUrl = config.getBaseUrl().trim();
171+
private String normalizeApiUrl(final String requestedUrl) {
172+
final String configuredUrl =
173+
requestedUrl == null || requestedUrl.isBlank()
174+
? config.getBaseUrl()
175+
: requestedUrl;
176+
final String normalizedUrl = configuredUrl.trim();
174177

175178
if (normalizedUrl.contains("/chat/completions")
176179
|| normalizedUrl.contains("/v1/chat/completions")) {

0 commit comments

Comments
 (0)