Skip to content

Commit f7e1475

Browse files
authored
docs: add "static" whitelist example to shell (#67)
1 parent dfd6b19 commit f7e1475

1 file changed

Lines changed: 33 additions & 9 deletions

File tree

docs/guide/rule-engines/shell.md

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,41 @@ esac
6060

6161
### Domain Allowlist
6262

63+
Command:
6364
```bash
64-
#!/bin/sh
65-
# Check against allowed domains
66-
ALLOWED="api.github.com api.gitlab.com"
65+
httpjail --sh "./rules.sh" -- curl https://api.github.com/repos
66+
```
6767

68-
for domain in $ALLOWED; do
69-
[ "$HTTPJAIL_HOST" = "$domain" ] && exit 0
70-
done
68+
In `whitelist.txt`:
69+
```
70+
api.github.com
71+
github.com
72+
raw.githubusercontent.com
73+
api.gitlab.com
74+
gitlab.com
75+
```
7176

72-
echo "Domain not allowed"
73-
exit 1
77+
In `rules.sh`:
78+
```bash
79+
#!/bin/sh
80+
# Check if host is in whitelist file
81+
82+
# Read whitelist file (one domain per line)
83+
WHITELIST_FILE="./whitelist.txt"
84+
85+
# Check if whitelist file exists
86+
if [ ! -f "$WHITELIST_FILE" ]; then
87+
echo "Whitelist file not found: $WHITELIST_FILE"
88+
exit 1
89+
fi
90+
91+
# Check if current host is in the whitelist (exact match)
92+
if grep -Fxq "$HTTPJAIL_HOST" "$WHITELIST_FILE"; then
93+
exit 0 # Allow
94+
else
95+
echo "Host $HTTPJAIL_HOST not in whitelist"
96+
exit 1 # Deny
97+
fi
7498
```
7599

76100
### Method-Based Restrictions
@@ -158,4 +182,4 @@ Avoid for:
158182
- High-throughput scenarios (use line processor mode)
159183
- Simple logic (use JavaScript)
160184

161-
For high-throughput scenarios, consider the [Line Processor](./line-processor.md) mode which maintains a single process.
185+
For high-throughput scenarios, consider the [Line Processor](./line-processor.md) mode which maintains a single process.

0 commit comments

Comments
 (0)