You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Instead of writing JavaScript, you can use a custom script to evaluate each request. The script receives environment variables for each request and returns an exit code to allow (0) or block (non-zero) the request. Any output to stdout becomes additional context in the 403 response.
173
-
174
-
```bash
175
-
# Simple script example
176
-
#!/bin/bash
177
-
if [ "$HTTPJAIL_HOST"="github.com" ] && [ "$HTTPJAIL_METHOD"="GET" ];then
If `--sh` has spaces, it's run through `sh`; otherwise it's executed directly.
191
-
192
-
**Environment variables provided to the script:**
193
-
194
-
-`HTTPJAIL_URL` - Full URL being requested
195
-
-`HTTPJAIL_METHOD` - HTTP method (GET, POST, etc.)
196
-
-`HTTPJAIL_HOST` - Hostname from the URL
197
-
-`HTTPJAIL_SCHEME` - URL scheme (http or https)
198
-
-`HTTPJAIL_PATH` - Path component of the URL
199
-
200
-
**Script requirements:**
201
-
202
-
- Exit code 0 allows the request
203
-
- Any non-zero exit code blocks the request
204
-
- stdout is captured and included in 403 responses as additional context
205
-
- stderr is logged for debugging but not sent to the client
206
-
207
-
> [!TIP]
208
-
> Script-based evaluation can also be used for custom logging! Your script can log requests to a database, send metrics to a monitoring service, or implement complex audit trails before returning the allow/deny decision.
209
-
210
-
### JavaScript (V8) Evaluation
146
+
## JavaScript (V8) Evaluation
211
147
212
148
httpjail includes first-class support for JavaScript-based request evaluation using Google's V8 engine. This provides flexible and powerful rule logic.
All request information is available via the `r` object:
173
+
237
174
-`r.url` - Full URL being requested (string)
238
175
-`r.method` - HTTP method (GET, POST, etc.)
239
176
-`r.host` - Hostname from the URL
@@ -259,7 +196,47 @@ All request information is available via the `r` object:
259
196
> [!NOTE]
260
197
> The `--js` flag conflicts with `--sh` and `--js-file`. Only one evaluation method can be used at a time.
261
198
262
-
### Advanced Options
199
+
## Script-Based Evaluation
200
+
201
+
Instead of writing JavaScript, you can use a custom script to evaluate each request. The script receives environment variables for each request and returns an exit code to allow (0) or block (non-zero) the request. Any output to stdout becomes additional context in the 403 response.
202
+
203
+
```bash
204
+
# Simple script example
205
+
#!/bin/bash
206
+
if [ "$HTTPJAIL_HOST"="github.com" ] && [ "$HTTPJAIL_METHOD"="GET" ];then
If `--sh` has spaces, it's run through `sh`; otherwise it's executed directly.
220
+
221
+
**Environment variables provided to the script:**
222
+
223
+
-`HTTPJAIL_URL` - Full URL being requested
224
+
-`HTTPJAIL_METHOD` - HTTP method (GET, POST, etc.)
225
+
-`HTTPJAIL_HOST` - Hostname from the URL
226
+
-`HTTPJAIL_SCHEME` - URL scheme (http or https)
227
+
-`HTTPJAIL_PATH` - Path component of the URL
228
+
229
+
**Script requirements:**
230
+
231
+
- Exit code 0 allows the request
232
+
- Any non-zero exit code blocks the request
233
+
- stdout is captured and included in 403 responses as additional context
234
+
- stderr is logged for debugging but not sent to the client
235
+
236
+
> [!TIP]
237
+
> Script-based evaluation can also be used for custom logging! Your script can log requests to a database, send metrics to a monitoring service, or implement complex audit trails before returning the allow/deny decision.
httpjail can run as a standalone proxy server without executing any commands. This is useful when you want to proxy multiple applications through the same httpjail instance. The server binds to localhost (127.0.0.1) only for security.
0 commit comments