使用這些 YAML 配置範例作為範本,透過 AI 掃描器掃描自訂 AI 應用程式端點。
尋找符合您 API 結構的配置模式並進行調整以開始掃描:
-
配置檔案結構:
custom部分的必填欄位和佔位符語法 -
簡單的 REST API:單一提示欄位,單一回應欄位
-
聊天完成 API 與訊息陣列:在訊息陣列中提示,並以陣列索引回應
-
巢狀請求和回應結構:深層巢狀的 JSON 負載
配置檔案結構
在配置檔案中的
custom部分定義AI掃描器如何與您的應用程式進行通信。您必須指定以下內容:-
端點 URL
-
HTTP 方法
-
標頭欄位,例如授權令牌或內容類型宣告
-
請求主體的 JSON 結構,包括文字提示的位置資訊
-
回應主體的 JSON 結構,包括模型輸出的位置信息
以下佔位符控制 AI 掃描器插入和提取資料的位置:
-
{{prompt}}:AI 掃描器在運行時將此佔位符替換為攻擊提示。 -
{{response}}:AI 掃描器從此位置資訊提取模型回應。 -
{{api_key}}:AI 掃描器會將此佔位符替換為TARGET_API_KEY環境變數的值。
重要將應用程式介面(API)金鑰儲存在環境變數中。不要直接在配置檔案中包含 API 金鑰。
|
簡單的 REST API
當您的AI應用程式公開一個簡單的REST端點,該端點在單一欄位中接受提示並在單一欄位中返回模型回應時,請使用此配置。在
request和response部分調整欄位名稱以符合您的API架構。version: 1.1.0
name: Simple REST API Scan
description: Security scan for a basic text generation endpoint
target:
# Replace with your endpoint URL
name: my-text-api
endpoint: https://api.example.com/v1/generate
api_key_env: TARGET_API_KEY
custom:
method: POST
headers:
Content-Type: application/json
Authorization: "Bearer {{api_key}}"
request:
# Replace field names to match your API schema
input: "{{prompt}}"
temperature: 0.2
response:
# Replace field names to match your API response
answer: "{{response}}"
settings:
concurrency: 10
attack_objectives:
- name: System Prompt Leakage
techniques:
- None
modifiers:
- None
- name: Sensitive Data Disclosure
techniques:
- None
modifiers:
- None
聊天完成 API 與訊息陣列
當您的AI應用程式遵循聊天完成API慣例時,請使用此配置,其中提示作為消息陣列發送,包含角色和內容欄位。此模式常見於自定義託管端點,這些端點遵循與OpenAI相同的請求結構。
system_prompt 欄位是 AI 掃描器在掃描過程中添加到對話中的頂層目標設定。它不會出現在請求正文中。version: 1.1.0
name: Chat Completions API Scan
description: Security scan for a chat-style AI endpoint
target:
# Replace with your endpoint URL
name: my-chat-api
endpoint: https://api.example.com/v1/chat/completions
api_key_env: TARGET_API_KEY
# AI Scanner prepends this to conversations during scanning
system_prompt: You are a helpful assistant.
custom:
method: POST
headers:
Content-Type: application/json
request:
# Replace model name with your deployed model
model: my-model-v1
messages:
- role: user
content: "{{prompt}}"
stream: false
response:
# Match the response structure of your API
choices:
- finish_reason: stop
index: 0
message:
content: "{{response}}"
role: assistant
settings:
concurrency: 10
attack_objectives:
- name: System Prompt Leakage
techniques:
- DAN (Do anything now)
modifiers:
- None
- name: Malicious Code Generation
techniques:
- Ignore all previous instructions
modifiers:
- Base64 Encoding
嵌套的請求和回應結構
當您的AI應用程式將提示和回應包裹在深層嵌套的JSON物件中時,例如包含元數據或配置參數的API,請使用此配置。
version: 1.1.0
name: Nested Structure API Scan
description: Security scan for an endpoint with nested JSON payloads
target:
# Replace with your endpoint URL
name: my-nested-api
endpoint: https://nlp.example.net/run
api_key_env: TARGET_API_KEY
custom:
method: POST
headers:
Content-Type: application/json
Authorization: "Token {{api_key}}"
request:
# Match the nested structure of your API request
payload:
prompt: "{{prompt}}"
config:
temperature: 0.1
max_tokens: 1000
response:
# Match the nested structure of your API response
data:
result:
message: "{{response}}"
settings:
concurrency: 5
attack_objectives:
- name: Sensitive Data Disclosure
techniques:
- Payload splitting
modifiers:
- Best-of-N Scrambling
- name: Agent Tool Definition Leakage
techniques:
- None
modifiers:
- None
