Skip to main content

High-performance URL reputation and phishing detection for MCP Gateway

Project description

URL Reputation (Rust)

Static URL policy checks for ContextForge and MCP Gateway resource fetches.

Features

  • Blocks resource fetches before execution with the resource_pre_fetch hook
  • Allows trusted domains or URL regex patterns to bypass later checks
  • Blocks configured domains, subdomains, or URL regex patterns
  • Blocks non-HTTPS URLs by default
  • Optional domain heuristics for high entropy, static IANA TLD validity, and Unicode security
  • Case-insensitive domain normalization for allowlist and blocklist entries
  • Pure static policy checks; no external reputation provider or threat-intel feed calls

Build

make install

Runtime Requirements

This plugin depends on cpex>=0.1.0,<0.2 and imports hook models from cpex.framework. The compiled Rust extension is mandatory; there is no Python fallback implementation.

Usage

The plugin runs on resource_pre_fetch before a resource URI is fetched.

Typical uses:

  • block known bad domains and subdomains
  • allow trusted internal URL patterns before enforcing HTTPS
  • reject insecure http:// resource fetches
  • enable lightweight domain heuristics for suspicious generated or Unicode domains

Configuration

config:
  whitelist_domains:
    - "example.com"
  allowed_patterns:
    - "^https://trusted\\.internal/.*"
  blocked_domains:
    - "malicious.example.com"
  blocked_patterns:
    - "casino"
    - "crypto"
  use_heuristic_check: false
  entropy_threshold: 3.65
  block_non_secure_http: true
Field Type Default Description
whitelist_domains set [] Domains and subdomains that bypass remaining checks
allowed_patterns list [] Regexes matched against the full trimmed URL; a match bypasses remaining checks
blocked_domains set [] Domains and subdomains that are always blocked unless allowlisted first
blocked_patterns list [] Regexes matched against the full trimmed URL; a match blocks the request
use_heuristic_check bool false Enable entropy, TLD, and Unicode domain checks for non-IP hosts
entropy_threshold float 3.65 Maximum allowed Shannon entropy for the domain
block_non_secure_http bool true Block URLs whose scheme is not https

Logic Workflow

  1. Trim and parse the URL.
  2. Extract the host/domain.
  3. Detect IPv4 or IPv6 hosts so domain heuristics can be skipped.
  4. Allow exact or parent-domain matches in whitelist_domains.
  5. Allow matches in allowed_patterns; this also bypasses HTTPS enforcement.
  6. Block non-HTTPS schemes when block_non_secure_http=true.
  7. Block exact or parent-domain matches in blocked_domains.
  8. Block matches in blocked_patterns.
  9. If heuristics are enabled for a non-IP host, block high-entropy domains, illegal static TLDs, or unsafe Unicode domains.

Returned Metadata

Allowed URLs return continue_processing=true.

Blocked URLs return continue_processing=false with a PluginViolation using code URL_REPUTATION_BLOCK. Violation details include the URL or domain involved in the decision.

resource_pre_fetch accepts an optional extensions parameter carrying OpenTelemetry trace context. When a trace context is present (via extensions.request.trace_id), the plugin emits operational metrics on result.metadata["url_reputation"] with the following schema:

result.metadata["url_reputation"] = {
    "total_checked": 1,                    # int — always 1; one URL is checked per call
    "total_blocked": 0,                     # int — 0 or 1; this call's outcome, not a running total
    "reputation_categories": [],            # list[str] — category slugs; empty when allowed
}

resource_pre_fetch evaluates exactly one URL per call with no running counter, so — mirroring rate_limiter's per-call allowed/throttled semantics — total_checked and total_blocked describe only the current call's outcome; the gateway aggregates counts across spans/time. When the URL is blocked, reputation_categories contains exactly one slug describing why (e.g. blocked_domain, insecure_scheme, high_entropy_domain, illegal_tld, unicode_spoofing, blocked_pattern, malformed_url, malformed_domain, internal_error).

Gating: Metrics are only emitted when a valid trace_id is present in the trace context (extensions.request.trace_id). No trace context means no result.metadata write at all.

Security Note (S1): The plugin never includes the raw URL or domain in result.metadata. Only counts and category slugs (derived from the plugin's static, hardcoded violation reasons) are reported; the actual URL/domain stays confined to PluginViolation.details on the blocking path, a separate channel unaffected by this metrics addition.

Limitations

  • Reputation data is static configuration only; there are no external provider lookups.
  • The IANA TLD list is compiled into the plugin and can lag newly delegated TLDs.
  • allowed_patterns intentionally runs before HTTPS enforcement, so trusted patterns can allow http:// URLs.
  • IP addresses skip domain heuristics.

Testing

make ci

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cpex_url_reputation-0.3.5.tar.gz (44.3 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

cpex_url_reputation-0.3.5-cp311-abi3-win_amd64.whl (846.3 kB view details)

Uploaded CPython 3.11+Windows x86-64

cpex_url_reputation-0.3.5-cp311-abi3-manylinux_2_34_x86_64.whl (927.9 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.34+ x86-64

cpex_url_reputation-0.3.5-cp311-abi3-manylinux_2_34_s390x.whl (982.9 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.34+ s390x

cpex_url_reputation-0.3.5-cp311-abi3-manylinux_2_34_ppc64le.whl (961.2 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.34+ ppc64le

cpex_url_reputation-0.3.5-cp311-abi3-manylinux_2_34_aarch64.whl (878.3 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.34+ ARM64

cpex_url_reputation-0.3.5-cp311-abi3-macosx_11_0_arm64.whl (829.8 kB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

File details

Details for the file cpex_url_reputation-0.3.5.tar.gz.

File metadata

  • Download URL: cpex_url_reputation-0.3.5.tar.gz
  • Upload date:
  • Size: 44.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for cpex_url_reputation-0.3.5.tar.gz
Algorithm Hash digest
SHA256 7fb5fa5d9f93ef5b49d7cd00080ccf322d24863ba2d9a79962f2a8c48b23ef7b
MD5 6b28c6a3406e0a9e25a20f592a3b42b0
BLAKE2b-256 657f3383be8316d497126506db5720b9c03c9206a030b4cc8ffbbcc612d811a5

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpex_url_reputation-0.3.5.tar.gz:

Publisher: release-rust-python-package.yaml on IBM/cpex-plugins

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cpex_url_reputation-0.3.5-cp311-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for cpex_url_reputation-0.3.5-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 826a2aa52345c2b0d2565a313f178a51fd63e97aac0d3fda2ff3b671612d5ef2
MD5 bc9d1e826df61ab7af476361a17c293e
BLAKE2b-256 d618bf243dc4cea0b6418411a3160163f1ac1eb0914ce87387827f21b655b774

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpex_url_reputation-0.3.5-cp311-abi3-win_amd64.whl:

Publisher: release-rust-python-package.yaml on IBM/cpex-plugins

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cpex_url_reputation-0.3.5-cp311-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for cpex_url_reputation-0.3.5-cp311-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 f8a0dbfcff0ea3106f46b19461f4acab2684cb51176ee48f92089070e86a6ea2
MD5 44c0ef22684188a5a5447a35dc5d57cb
BLAKE2b-256 c02e48a342940f31ab67d333c3f99c5feecddea57807a77cb4ae854817ae6042

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpex_url_reputation-0.3.5-cp311-abi3-manylinux_2_34_x86_64.whl:

Publisher: release-rust-python-package.yaml on IBM/cpex-plugins

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cpex_url_reputation-0.3.5-cp311-abi3-manylinux_2_34_s390x.whl.

File metadata

File hashes

Hashes for cpex_url_reputation-0.3.5-cp311-abi3-manylinux_2_34_s390x.whl
Algorithm Hash digest
SHA256 610d9bec0dfa4cb9435777a452fac31d08f4ea0957d4eb6aff8aa133f4b1bceb
MD5 4be7bccceecd0a15f926af7e5579b287
BLAKE2b-256 d039a24cfd1b72af5068153fa7349bb7043095e156df6f7396a6fd3a38fc68e4

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpex_url_reputation-0.3.5-cp311-abi3-manylinux_2_34_s390x.whl:

Publisher: release-rust-python-package.yaml on IBM/cpex-plugins

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cpex_url_reputation-0.3.5-cp311-abi3-manylinux_2_34_ppc64le.whl.

File metadata

File hashes

Hashes for cpex_url_reputation-0.3.5-cp311-abi3-manylinux_2_34_ppc64le.whl
Algorithm Hash digest
SHA256 71947ec693033725ef2ce4c29304b72ca4bbbefab4eca0791ee653df2b8e80ba
MD5 c859056a91335741e625c0f119ee58f6
BLAKE2b-256 3f842b39e88e1f960d3021a20117199f25c6841886a2f0b0e2f660670939dce1

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpex_url_reputation-0.3.5-cp311-abi3-manylinux_2_34_ppc64le.whl:

Publisher: release-rust-python-package.yaml on IBM/cpex-plugins

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cpex_url_reputation-0.3.5-cp311-abi3-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for cpex_url_reputation-0.3.5-cp311-abi3-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 d59fc44a1e791a9950ceb4fb7415be5626d58d507e43cc7f1be86c5ad95f6533
MD5 9fe10dc1ae15db89e665b1b48f183a8c
BLAKE2b-256 e94eba2f278fd0c175de12fde83f99ccac3e36561cc03537f75fb6e9870e8f31

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpex_url_reputation-0.3.5-cp311-abi3-manylinux_2_34_aarch64.whl:

Publisher: release-rust-python-package.yaml on IBM/cpex-plugins

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cpex_url_reputation-0.3.5-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cpex_url_reputation-0.3.5-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 72bb83b77540584f38d41ae1142bc1ddbd83685638b9b89205417d2753753435
MD5 96fbca4bb89d0ce25ae86487ceb14d70
BLAKE2b-256 717acea96f6373f7d963b846d156197d64e603c194d752daef39601ebdab0e12

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpex_url_reputation-0.3.5-cp311-abi3-macosx_11_0_arm64.whl:

Publisher: release-rust-python-package.yaml on IBM/cpex-plugins

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page