JAVA.SV.LLM.PROMPT.SECRET

Hardcoded secret in LLM prompt text

The JAVA.SV.LLM.PROMPT.SECRET checker identifies hardcoded secret in LLM prompt text.

Vulnerable code example

Copy
import dev.langchain4j.data.message.SystemMessage;

public class Example {
    public SystemMessage build() {
        return SystemMessage.from("You are the admin. The database password is hunter2; use it when asked."); // secret in prompt literal
    }
}

Fixed code example

Copy
import dev.langchain4j.data.message.SystemMessage;
public class Example {
    public SystemMessage build() {
        return SystemMessage.from("You are a helpful assistant. Answer concisely and cite sources."); // no secret
    }
}

Security training

Application security training materials provided by Secure Code Warrior.