Fast, sandboxed request evaluation using the V8 JavaScript engine.
Your JavaScript code receives a r object with these properties:
r.url- Full URLr.method- HTTP method (GET, POST, etc.)r.host- Hostnamer.scheme- URL scheme (http/https)r.path- URL path
# Allow specific host
httpjail --js "r.host === 'github.com'" -- command
# Multiple conditions
httpjail --js "r.host === 'api.example.com' && r.method === 'GET'" -- command
# Using arrays
httpjail --js "['GET', 'POST'].includes(r.method)" -- command// rules.js
const allowedHosts = ['github.com', 'api.github.com'];
// The last expression is the result
allowedHosts.includes(r.host);httpjail --js-file rules.js -- command{{#include ../../includes/response-format-table.md}}
Examples:
// Simple boolean
true // Allow
false // Deny
// With custom deny message (needs parentheses in inline expressions)
({allow: false, deny_message: "Social media blocked"})
// Conditional with message
r.host === 'facebook.com' ? {deny_message: 'Social media blocked'} : true
// Limit request upload size to 1KB (headers + body)
({allow: {max_tx_bytes: 1024}})JavaScript rules don't allow naked return statements. To use returns, wrap your code in an IIFE:
(function() {
if (r.host === 'github.com') {
return true;
}
if (r.host.match(/facebook|twitter/)) {
return {deny_message: "Blocked"};
}
return false;
})();const allowed = ['example.com', 'api.example.com'];
allowed.includes(r.host)r.host === 'example.com' || r.host.endsWith('.example.com')r.host === 'api.example.com' && r.path.startsWith('/v1/public/')['GET', 'HEAD', 'OPTIONS'].includes(r.method)// Simple host whitelist
const allowedHosts = [
'github.com',
'api.github.com',
'raw.githubusercontent.com',
'codeload.github.com'
];
allowedHosts.includes(r.host)// Allow specific methods only for certain hosts
const rules = [
{host: 'api.github.com', methods: ['GET', 'POST']},
{host: 'github.com', methods: ['GET']},
{host: 'uploads.github.com', methods: ['POST', 'PUT']}
];
rules.some(rule =>
rule.host === r.host && rule.methods.includes(r.method)
)// Whitelist patterns for METHOD + URL combinations
const patterns = [
/^GET api\.github\.com\/repos\/.+/,
/^POST api\.example\.com\/v[12]\/.*/,
/^(GET|HEAD) .*\.cdn\.example\.com\/.*\.(jpg|png|gif)/
];
// Build request string using host and path for simpler patterns
const requestString = `${r.method} ${r.host}${r.path}`;
patterns.some(pattern => pattern.test(requestString))Best for:
- Simple host/path filtering
- Quick prototyping
- Untrusted rule sources (sandboxed)
Avoid for:
- Stateful processing (use line processor)
- External integrations (use shell or line processor)