Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

ammario
Copy link
Member

@ammario ammario commented Sep 11, 2025

Summary
Provide the requester IP to both rule engines and propagate it through the proxy, enabling IP-aware policies in JavaScript and shell scripts.

Changes

  • JavaScript (V8) rule engine: add r.requester_ip to the r object
  • Script rule engine: export HTTPJAIL_REQUESTER_IP for each evaluation
  • RuleEngineTrait: accept requester_ip and plumb it through all HTTP/HTTPS paths (transparent TLS and CONNECT)
  • Proxy: includes upstream bind improvements from main (IP_FREEBIND) to stabilize Linux strong-mode tests
  • Docs: README documents r.requester_ip (JS) and HTTPJAIL_REQUESTER_IP (scripts)
  • Cleanup: remove obsolete pattern rule engine after merge with main

Use cases

  • IP-based allow/deny lists
  • Per-subnet policies (e.g., allow same /24 only)
  • IP-aware rate limiting and audit logging

Examples
JavaScript:

// Allow only calls from the same /24 as the requester
(() => {
  const net24 = r.requester_ip.split('.').slice(0,3).join('.') + '.';
  if (r.host === 'api.internal.local' && r.scheme === 'https' && r.method === 'GET') {
    return true;
  }
  r.block_message = `Denied for ${r.requester_ip}`;
  return false;
})()

Script:

#!/bin/sh
# allow local network only
case "$HTTPJAIL_REQUESTER_IP" in
  192.168.1.*) exit 0 ;;
  *) echo "Request from $HTTPJAIL_REQUESTER_IP not allowed"; exit 1 ;;
esac

Test plan

  • cargo build and local script integration tests pass
  • CI: Linux + macOS integrations, format, and udeps are passing; remaining jobs are running and will be monitored

Notes

  • No CLI changes in this PR beyond what already landed on main; this patch focuses on requester IP exposure and proxy/test stability.

Co-authored-by: ammario [email protected]

- Pass requester IP address through all proxy handlers
- Add HTTPJAIL_REQUESTER_IP environment variable to script execution
- Update RuleEngineTrait to accept requester IP as required parameter
- Add test to verify requester IP is correctly passed to scripts
- Update README documentation with new environment variable

This allows scripts to make decisions based on the client's IP address,
enabling IP-based filtering, rate limiting, or custom logging scenarios.
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex Review: Here are some suggestions.

Reply with @codex fix comments to fix any unresolved comments.

About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".

Comment on lines 45 to +48

#[async_trait]
pub trait RuleEngineTrait: Send + Sync {
async fn evaluate(&self, method: Method, url: &str) -> EvaluationResult;
async fn evaluate(&self, method: Method, url: &str, requester_ip: &str) -> EvaluationResult;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Update tests for new requester_ip parameter

The trait method RuleEngineTrait::evaluate now requires a requester_ip argument, but the unit tests still invoke engine.evaluate(method, url) with the old two-parameter signature (see src/rules/script.rs and src/rules.rs). Running cargo test will fail to compile until those call sites provide an IP value or the API offers a backwards-compatible wrapper. Consider updating the tests to pass a dummy IP so the suite builds again.

Useful? React with 👍 / 👎.

blink-so bot and others added 7 commits September 11, 2025 14:15
Fix tests to pass new parameter after API change.

Co-authored-by: ammario <[email protected]>
…ait\n\n- Add r.requester_ip to JS context\n- Update V8JsRuleEngine to accept requester_ip\n- Adjust tests to pass requester_ip\n- Remove obsolete pattern engine after merge\n\nCo-authored-by: ammario <[email protected]>
Copy link
Contributor

blink-so bot commented Sep 12, 2025

Pushed a rustfmt cleanup to fix the format job. Current CI status:

  • Linux Tests: passed
  • macOS Integration Tests: passed
  • Format: passed
  • Unused dependency check: passed
  • Clippy and Weak Mode Integration: still running

Feature notes:

  • JS rule engine now exposes r.requester_ip
  • README updated to document r.requester_ip and script env HTTPJAIL_REQUESTER_IP

I’ll keep an eye on the remaining jobs and follow up if anything fails.

@blink-so blink-so bot changed the title feat: add HTTPJAIL_REQUESTER_IP environment variable for scripts feat(rules): expose requester IP to JS (r.requester_ip) and scripts (HTTPJAIL_REQUESTER_IP) Sep 12, 2025
Copy link
Contributor

blink-so bot commented Sep 12, 2025

CI is green on the latest commit (031d8a7). All 6 jobs in the Tests workflow succeeded:

  • macOS Integration Tests ✅
  • Linux Tests (including weak + jail integrations) ✅
  • Unused dependency check (cargo-udeps) ✅
  • Format ✅
  • Clippy (ubuntu-latest-8-cores) ✅
  • Clippy (macos-latest) ✅

No code changes were necessary. Do you want me to request review or proceed with merge once approvals are in?

Resolve README.md conflicts and retain Advanced Options heading; integrate r.requester_ip in JS API.

Co-authored-by: ammario <[email protected]>
Copy link
Contributor

blink-so bot commented Sep 12, 2025

Updated the PR branch with the latest main and resolved a README.md merge conflict.

Details:

  • Kept main’s "## Advanced Options" heading and removed the duplicate JS section that was causing the conflict
  • Integrated the r.requester_ip field into the JavaScript API list (docs)

Commit: 1e91f80

CI should kick off on this update. I’ll monitor and follow up if anything goes red. If you prefer a rebase instead of a merge update, say the word and I’ll switch it.

@ammario ammario enabled auto-merge (squash) September 13, 2025 16:31
@ammario ammario merged commit 340606d into main Sep 13, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant