Skip to content

secrets

シークレット (API キー、トークン、秘密鍵など) 検出ルールのビルダーを作成します。

シグネチャ

ts
const builder = secrets(options?);

パラメーター

パラメーター説明
options.namestringルール名 (省略時は自動生成)

メソッド

メソッド戻り値説明
.exclude(...types)DetectorBuilder指定したタイプを検出対象から除外
.only(...types)DetectorBuilder指定したタイプのみ検出
.scope(...tools)DetectorBuilder特定ツールに限定 (string | RegExp)
.block(message?)Rule違反時にブロック (severity: "error")
.warn(message?)Rule違反を警告 (severity: "warn")
.log(message?)Rule違反をログ記録 (severity: "info")

検出タイプ

タイプ検出対象信頼度
aws_access_keyAWS アクセスキー (AKIA...)0.95
aws_secret_keyAWS シークレットキー0.60
github_tokenGitHub トークン (ghp_, github_pat_)0.95
slack_tokenSlack トークン (xoxb-, xoxp-)0.95
bearer_tokenBearer トークン0.85
private_key秘密鍵 (BEGIN PRIVATE KEY)0.99
api_key汎用 API キーパターン (api_key=...)0.75
google_api_keyGoogle API キー (AIza...)0.90
stripe_keyStripe キー (sk_live_, sk_test_)0.95
generic_secret汎用シークレット (password=, token=)0.70

戻り値

DetectorBuilder — ターミナルメソッドで Rule を返します。

使用例

基本

ts
import { secrets } from "open-mcp-guardrails";

secrets().block();

誤検知の多いタイプを除外

ts
secrets().exclude("generic_secret", "aws_secret_key").block();

特定タイプのみ

ts
secrets().only("github_token", "stripe_key").block();

特定ツールに限定

ts
secrets().scope("filesystem__read_file").block();
secrets().scope(/^filesystem__/).warn();

JSON 設定

guardrails.json での設定例:

json
{ "type": "secrets", "action": "block" }
json
{ "type": "secrets", "action": "block", "exclude": ["generic_secret", "aws_secret_key"] }
json
{ "type": "secrets", "action": "block", "only": ["github_token", "stripe_key"] }
json
{ "type": "secrets", "action": "block", "scope": ["filesystem__read_file"] }
json
{ "type": "secrets", "action": "warn", "scope": ["/^filesystem__/"] }

関連