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
Copy file name to clipboardExpand all lines: CLAUDE.md
+56-4Lines changed: 56 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,17 @@ protocol), we must establish a timeout for the operation.
10
10
11
11
Timeouts must not preclude long-running connections such as GRPC or WebSocket.
12
12
13
+
## Building
14
+
15
+
For faster builds during development and debugging, use the `fast` profile:
16
+
17
+
```bash
18
+
cargo build --profile fast
19
+
```
20
+
21
+
This profile inherits from release mode but uses lower optimization levels and disables LTO
22
+
for significantly faster build times while still providing reasonable performance.
23
+
13
24
## Testing
14
25
15
26
When writing tests, prefer pure rust solutions over shell script wrappers.
@@ -18,6 +29,16 @@ When testing behavior outside of the strong jailing, use `--weak` for an environ
18
29
invocation of the tool. `--weak` works by setting the `HTTP_PROXY` and `HTTPS_PROXY` environment
19
30
variables to the proxy address.
20
31
32
+
### Integration Tests
33
+
34
+
The integration tests use the `HTTPJAIL_BIN` environment variable to determine which binary to test.
35
+
Always set this to the most up-to-date binary before running tests:
36
+
37
+
```bash
38
+
export HTTPJAIL_BIN=/path/to/httpjail
39
+
cargo test --test linux_integration
40
+
```
41
+
21
42
## Cargo Cache
22
43
23
44
Occasionally you will encounter permissions issues due to running the tests under sudo. In these cases,
@@ -60,12 +81,43 @@ In regular operation of the CLI-only jail (non-server mode), info and warn logs
60
81
61
82
The Linux CI tests run on a self-hosted runner (`ci-1`) in GCP. Only Coder employees can directly SSH into this instance for debugging.
62
83
63
-
To debug CI failures on Linux:
84
+
The CI workspace is located at `/home/ci/actions-runner/_work/httpjail/httpjail`. **IMPORTANT: Never modify files in this directory directly as it will interfere with running CI jobs.**
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.
170
-
171
-
```bash
172
-
# Simple script example
173
-
#!/bin/bash
174
-
if [ "$HTTPJAIL_HOST"="github.com" ] && [ "$HTTPJAIL_METHOD"="GET" ];then
If `--sh` has spaces, it's run through `sh`; otherwise it's executed directly.
188
-
189
-
**Environment variables provided to the script:**
190
-
191
-
-`HTTPJAIL_URL` - Full URL being requested
192
-
-`HTTPJAIL_METHOD` - HTTP method (GET, POST, etc.)
193
-
-`HTTPJAIL_HOST` - Hostname from the URL
194
-
-`HTTPJAIL_SCHEME` - URL scheme (http or https)
195
-
-`HTTPJAIL_PATH` - Path component of the URL
196
-
-`HTTPJAIL_REQUESTER_IP` - IP address of the client making the request
197
-
198
-
**Script requirements:**
199
-
200
-
- Exit code 0 allows the request
201
-
- Any non-zero exit code blocks the request
202
-
- stdout is captured and included in 403 responses as additional context
203
-
- stderr is logged for debugging but not sent to the client
204
-
205
-
> [!TIP]
206
-
> 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.
207
-
208
-
### JavaScript (V8) Evaluation
146
+
## JavaScript (V8) Evaluation
209
147
210
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
+
235
174
-`r.url` - Full URL being requested (string)
236
175
-`r.method` - HTTP method (GET, POST, etc.)
237
176
-`r.host` - Hostname from the URL
@@ -258,8 +197,48 @@ All request information is available via the `r` object:
258
197
> [!NOTE]
259
198
> The `--js` flag conflicts with `--sh` and `--js-file`. Only one evaluation method can be used at a time.
260
199
261
-
### Advanced Options
200
+
## Script-Based Evaluation
201
+
202
+
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.
203
+
204
+
```bash
205
+
# Simple script example
206
+
#!/bin/bash
207
+
if [ "$HTTPJAIL_HOST"="github.com" ] && [ "$HTTPJAIL_METHOD"="GET" ];then
If `--sh` has spaces, it's run through `sh`; otherwise it's executed directly.
221
+
222
+
**Environment variables provided to the script:**
223
+
224
+
-`HTTPJAIL_URL` - Full URL being requested
225
+
-`HTTPJAIL_METHOD` - HTTP method (GET, POST, etc.)
226
+
-`HTTPJAIL_HOST` - Hostname from the URL
227
+
-`HTTPJAIL_SCHEME` - URL scheme (http or https)
228
+
-`HTTPJAIL_PATH` - Path component of the URL
229
+
-`HTTPJAIL_REQUESTER_IP` - IP address of the client making the request
230
+
231
+
**Script requirements:**
232
+
233
+
- Exit code 0 allows the request
234
+
- Any non-zero exit code blocks the request
235
+
- stdout is captured and included in 403 responses as additional context
236
+
- stderr is logged for debugging but not sent to the client
237
+
238
+
> [!TIP]
239
+
> 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