Skip to content

List Firewall Rules

Returns all firewall rules for the authenticated user, ordered by priority (highest first).

GET /v1/firewall-rules

None. This endpoint returns all rules for the authenticated user.

import Tokenrouter from 'tokenrouter';
const client = new Tokenrouter({
apiKey: process.env.TOKENROUTER_API_KEY
});
const response = await client.firewallRules.list();
// Rules are ordered by priority (highest first)
response.data.forEach(rule => {
console.log(`${rule.name} (Priority: ${rule.priority})`);
console.log(` Scope: ${rule.scope}`);
console.log(` Type: ${rule.type}`);
console.log(` Action: ${rule.action}`);
console.log(` Pattern: ${rule.pattern}`);
console.log(` Enabled: ${rule.is_enabled}`);
console.log('---');
});
{
"data": [
{
"id": 123,
"user_id": 456,
"name": "Block Credit Cards",
"is_enabled": true,
"priority": 100,
"scope": "prompt",
"type": "regex",
"pattern": "\\d{4}[\\s-]?\\d{4}[\\s-]?\\d{4}[\\s-]?\\d{4}",
"action": "block",
"replacement": null,
"created_at": "2025-11-10T12:00:00Z",
"updated_at": "2025-11-10T12:00:00Z"
},
{
"id": 124,
"user_id": 456,
"name": "Mask Email Addresses",
"is_enabled": true,
"priority": 80,
"scope": "response",
"type": "regex",
"pattern": "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}",
"action": "mask",
"replacement": "[EMAIL_REDACTED]",
"created_at": "2025-11-10T13:00:00Z",
"updated_at": "2025-11-10T13:00:00Z"
},
{
"id": 125,
"user_id": 456,
"name": "Warn on Profanity",
"is_enabled": false,
"priority": 50,
"scope": "response",
"type": "substring",
"pattern": "inappropriate",
"action": "warn",
"replacement": null,
"created_at": "2025-11-10T14:00:00Z",
"updated_at": "2025-11-10T14:00:00Z"
}
]
}
FieldTypeDescription
idintegerUnique rule identifier
user_idintegerOwner user ID
namestringRule name
is_enabledbooleanWhether rule is active
priorityintegerRule priority (-1000 to 1000)
scopestringprompt or response
typestringsubstring or regex
patternstringPattern to match
actionstringblock, mask, or warn
replacementstring|nullReplacement text (only for mask action)
created_atstringISO timestamp of creation
updated_atstringISO timestamp of last update

Rules are returned in the order they will be evaluated during request processing:

  1. By Priority (DESC) - Highest priority first
  2. By ID (ASC) - Older rules first when priorities are equal

Example order:

Priority 100 (Block Credit Cards) → Evaluated first
Priority 80 (Mask Emails) → Evaluated second
Priority 50 (Warn Profanity) → Evaluated third
const response = await client.firewallRules.list();
// Get only prompt rules
const promptRules = response.data.filter(r => r.scope === 'prompt');
// Get only response rules
const responseRules = response.data.filter(r => r.scope === 'response');
console.log(`Prompt rules: ${promptRules.length}`);
console.log(`Response rules: ${responseRules.length}`);
const response = await client.firewallRules.list();
// Group by action
const blockRules = response.data.filter(r => r.action === 'block');
const maskRules = response.data.filter(r => r.action === 'mask');
const warnRules = response.data.filter(r => r.action === 'warn');
console.log(`Block rules: ${blockRules.length}`);
console.log(`Mask rules: ${maskRules.length}`);
console.log(`Warn rules: ${warnRules.length}`);
const response = await client.firewallRules.list();
// Get only enabled rules
const activeRules = response.data.filter(rule => rule.is_enabled);
console.log(`${activeRules.length} active rules out of ${response.data.length} total`);
// List active block rules (most critical)
const activeBlockRules = activeRules.filter(r => r.action === 'block');
activeBlockRules.forEach(rule => {
console.log(`⚠️ ${rule.name} - blocks "${rule.pattern}"`);
});
const response = await client.firewallRules.list();
// Find rules with no replacement text for mask action
const maskRulesWithoutReplacement = response.data.filter(
r => r.action === 'mask' && !r.replacement
);
if (maskRulesWithoutReplacement.length > 0) {
console.log('Rules using default [redacted] replacement:');
maskRulesWithoutReplacement.forEach(r => console.log(` - ${r.name}`));
}
// Find regex rules (more complex)
const regexRules = response.data.filter(r => r.type === 'regex');
console.log(`${regexRules.length} regex rules (may need testing)`);

If no rules exist, the response is an empty array:

{
"data": []
}

Generate a security report of all firewall protections:

const rules = await client.firewallRules.list();
console.log('=== Firewall Security Audit ===\n');
console.log('🚫 BLOCKED PATTERNS:');
rules.data
.filter(r => r.action === 'block' && r.is_enabled)
.forEach(r => console.log(` ${r.name}: ${r.pattern}`));
console.log('\n🎭 MASKED PATTERNS:');
rules.data
.filter(r => r.action === 'mask' && r.is_enabled)
.forEach(r => console.log(` ${r.name}: ${r.pattern}${r.replacement}`));
console.log('\n⚠️ WARNING PATTERNS:');
rules.data
.filter(r => r.action === 'warn' && r.is_enabled)
.forEach(r => console.log(` ${r.name}: ${r.pattern}`));
import fs from 'fs';
const rules = await client.firewallRules.list();
// Export to JSON
const backup = {
exported_at: new Date().toISOString(),
rules: rules.data.map(r => ({
name: r.name,
priority: r.priority,
is_enabled: r.is_enabled,
scope: r.scope,
type: r.type,
pattern: r.pattern,
action: r.action,
replacement: r.replacement
}))
};
fs.writeFileSync('firewall-backup.json', JSON.stringify(backup, null, 2));
console.log(`Exported ${backup.rules.length} rules`);