Skip to content

Commit 08cc1ea

Browse files
committed
Clean up README
1 parent 5353fcb commit 08cc1ea

1 file changed

Lines changed: 47 additions & 70 deletions

File tree

README.md

Lines changed: 47 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -126,39 +126,15 @@ httpjail creates an isolated network environment for the target process, interce
126126
- macOS 10.15+ (Catalina or later)
127127
- No special permissions required (runs in weak mode)
128128

129-
## Usage Examples
130-
131-
### Basic Usage
132-
133-
```bash
134-
# Simple allow/deny rules
135-
httpjail --js "r.host === 'api.github.com'" -- git pull
136-
137-
# Multiple allow patterns using regex
138-
httpjail \
139-
--js "/github\.com$/.test(r.host) || /githubusercontent\.com$/.test(r.host)" \
140-
-- npm install
141-
142-
# Deny telemetry while allowing everything else
143-
httpjail \
144-
--js "!/telemetry\.|analytics\.|sentry\./.test(r.host)" \
145-
-- ./application
146-
147-
# Method-specific rules
148-
httpjail \
149-
--js "(r.method === 'GET' && /api\..*\.com$/.test(r.host)) || (r.method === 'POST' && !/telemetry\./.test(r.host)) || r.method !== 'GET' && r.method !== 'POST'" \
150-
-- ./application
151-
```
152-
153-
### Configuration File
129+
## Configuration File
154130

155131
Create a `rules.js` file with your JavaScript evaluation logic:
156132

157133
```javascript
158134
// rules.js
159135
// Allow GitHub GET requests, block telemetry, allow everything else
160-
(r.method === 'GET' && /github\.com$/.test(r.host)) ||
161-
(!/telemetry/.test(r.host))
136+
(r.method === "GET" && /github\.com$/.test(r.host)) ||
137+
!/telemetry/.test(r.host);
162138
```
163139

164140
Use the config:
@@ -167,47 +143,7 @@ Use the config:
167143
httpjail --js-file rules.js -- ./my-application
168144
```
169145

170-
### Script-Based Evaluation
171-
172-
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
178-
exit 0 # Allow the request
179-
else
180-
exit 1 # Block the request
181-
fi
182-
183-
# Use the script
184-
httpjail --sh ./check_request.sh -- curl https://github.com
185-
186-
# Inline script (with spaces, executed via shell)
187-
httpjail --sh '[ "$HTTPJAIL_HOST" = "github.com" ] && exit 0 || exit 1' -- git pull
188-
```
189-
190-
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
211147

212148
httpjail includes first-class support for JavaScript-based request evaluation using Google's V8 engine. This provides flexible and powerful rule logic.
213149

@@ -234,6 +170,7 @@ httpjail --js "(r.block_message = 'Social media blocked', !r.host.includes('face
234170
**JavaScript API:**
235171

236172
All request information is available via the `r` object:
173+
237174
- `r.url` - Full URL being requested (string)
238175
- `r.method` - HTTP method (GET, POST, etc.)
239176
- `r.host` - Hostname from the URL
@@ -259,7 +196,47 @@ All request information is available via the `r` object:
259196
> [!NOTE]
260197
> The `--js` flag conflicts with `--sh` and `--js-file`. Only one evaluation method can be used at a time.
261198
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
207+
exit 0 # Allow the request
208+
else
209+
exit 1 # Block the request
210+
fi
211+
212+
# Use the script
213+
httpjail --sh ./check_request.sh -- curl https://github.com
214+
215+
# Inline script (with spaces, executed via shell)
216+
httpjail --sh '[ "$HTTPJAIL_HOST" = "github.com" ] && exit 0 || exit 1' -- git pull
217+
```
218+
219+
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.
238+
239+
## Advanced Options
263240

264241
```bash
265242
# Verbose logging
@@ -277,7 +254,7 @@ HTTPJAIL_HTTP_BIND=3128 HTTPJAIL_HTTPS_BIND=3129 httpjail --server --js "true"
277254
HTTPJAIL_HTTP_BIND=192.168.1.100:8080 httpjail --server --js "true"
278255
```
279256

280-
### Server Mode
257+
## Server Mode
281258

282259
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.
283260

0 commit comments

Comments
 (0)