JAVA.SV.LLM.INPUT.UNBOUNDED
LLM に渡される無制限の入力
JAVA.SV.LLM.INPUT.UNBOUNDED チェッカーは、LLM に渡される無制限の入力を特定します。
脆弱性とリスク
LLM への無制限の入力を許容すると、トークン使用量やその他のリソース消費量が増加する可能性があります。
軽減と防止
LLM に送信する前に、入力のサイズを検証し、制限を設けます。
脆弱コード例
コピー
import org.springframework.ai.chat.client.ChatClient;
public class Example {
private final ChatClient chatClient;
public Example(ChatClient chatClient) {
this.chatClient = chatClient;
}
public String summarize(String documentText) {
return chatClient.prompt()
.user(documentText) // entire document forwarded with no size check
.call()
.content();
}
}
修正コード例
コピー
import org.springframework.ai.chat.client.ChatClient;
public class Example {
private final ChatClient chatClient;
public Example(ChatClient chatClient) {
this.chatClient = chatClient;
}
public String summarize(String documentText) {
String boundedText = documentText.length() > 4000
? documentText.substring(0, 4000)
: documentText;
return chatClient.prompt()
.user(boundedText)
.call()
.content();
}
}
セキュリティトレーニング
Secure Code Warrior が提供しているアプリケーションセキュリティトレーニング教材。