Skip to content

fix(plugins): recover missing Rust implementation for url_reputation plugin#38

Merged
lucarlig merged 2 commits intomainfrom
recover-url-reputation-rust-implementation
Apr 20, 2026
Merged

fix(plugins): recover missing Rust implementation for url_reputation plugin#38
lucarlig merged 2 commits intomainfrom
recover-url-reputation-rust-implementation

Conversation

@msureshkumar88
Copy link
Copy Markdown
Collaborator

@msureshkumar88 msureshkumar88 commented Apr 20, 2026

Closes: #37

Summary

This PR recovers the complete Rust implementation for the url_reputation plugin that was lost during migration from mcp-context-forge to the cpex-plugins monorepo. The plugin now has full functionality with all Rust source files, tests, benchmarks, and documentation properly integrated.

Problem

The url_reputation plugin directory existed in cpex-plugins but only contained a stub src/lib.rs file with minimal PyO3 boilerplate. The complete Rust implementation (707-line engine, filters, types, benchmarks) was missing, making the plugin non-functional.

Solution

Recovered all missing files from mcp-context-forge git history (commit 8bb308c50 from March 22, 2026) and properly integrated them into the cpex-plugins repository structure.

Changes

Recovered Rust Source Files (Commit 1: b6eae38)

Core Implementation:

  • src/engine.rs (707 lines) - Core URL reputation validation engine
  • src/types.rs (79 lines) - Type definitions and PyO3 bindings
  • src/lib.rs - Updated PyO3 module entry point

Filter Modules:

  • src/filters/mod.rs - Filter module declarations
  • src/filters/heuristic.rs (92 lines) - Entropy-based heuristic checks
  • src/filters/iana_tlds.rs (364 lines) - IANA TLD validation
  • src/filters/patterns.rs (26 lines) - Pattern-based filtering

Benchmarks:

  • benches/url_validation.rs (241 lines) - Performance benchmarks

Documentation & Support:

  • README.md (174 lines) - Complete usage documentation
  • compare_performance.py (241 lines) - Performance comparison script
  • bench_config.json (280 lines) - Benchmark configuration
  • deny.toml (27 lines) - Cargo-deny license policy

Tests:

  • tests/test_url_reputation.py (583 lines) - Enhanced unit tests

Configuration Updates:

  • Updated Cargo.toml with required dependencies:
    • idna (1.1.0) - Internationalized domain name support
    • url (2.5.8) - URL parsing
    • regex (1.12.3) - Pattern matching
    • phf (0.13.1) - Perfect hash functions for efficient TLD lookups
    • unicode-script (0.5.8), unicode-security (0.1.2) - Domain validation
    • criterion (0.8.2) - Benchmarking
  • Fixed test imports from plugins.url_reputation to cpex_url_reputation
  • Added _RUST_AVAILABLE flag for proper module detection

Removed Python Fallback Logic (Commit 2: f92ba48)

  • Modified URLReputationPlugin.__init__ to raise RuntimeError if Rust module is not available
  • Removed all Python fallback tests (test_python_* functions - 9 tests)
  • Removed Rust error fallback test (test_rust_error_fallback_blocks_url)
  • Plugin now enforces Rust-only operation for consistency and performance
  • Clear error message guides users to run make install if Rust module is missing

Features

The plugin now provides complete functionality including:

  • URL Reputation Validation: Configurable policies for URL filtering
  • Heuristic Checks: Entropy-based analysis for suspicious domains
  • IANA TLD Validation: Validates against official IANA TLD list
  • Pattern-Based Filtering: Allow/block lists with regex support
  • Domain Filtering: Whitelist/blocklist with subdomain matching
  • HTTP/HTTPS Enforcement: Configurable scheme validation
  • Performance: Rust implementation provides significant speed improvements

Testing

Build Verification

cd plugins/rust/python-package/url_reputation
make install  # ✅ Successful build

Test Results

Rust Unit Tests:

running 24 tests
test result: ok. 24 passed; 0 failed; 0 ignored; 0 measured

Python Integration Tests:

22 passed, 9 skipped in 0.10s
✅ All tests passing
⏭️ 9 tests skipped (Rust-specific features not tested in Python)
❌ 0 tests failed

Test Coverage

  • ✅ Whitelisted domain and subdomain matching
  • ✅ Blocked domain and pattern detection
  • ✅ HTTP/HTTPS scheme enforcement
  • ✅ Internationalized domain handling
  • ✅ Mixed case domain normalization
  • ✅ URL with port handling
  • ✅ Configuration validation
  • ✅ Error handling and safety fallbacks

Breaking Changes

None. The plugin was non-functional before this PR, so this is purely additive functionality.

Migration Notes

For users who had the plugin directory but couldn't use it:

  1. Pull the latest changes
  2. Run make install in the plugin directory
  3. The plugin will now work correctly with full Rust functionality

If the Rust module fails to install, the plugin will raise a clear error:

RuntimeError: Rust url_reputation_rust module is required but not available. 
Please ensure the plugin is properly installed with: make install

Checklist

  • All Rust source files recovered from git history
  • Plugin builds successfully with make install
  • All Rust unit tests pass (24 tests)
  • All Python integration tests pass (22 tests)
  • Cargo.toml includes all required dependencies
  • Documentation is complete and accurate
  • Plugin manifest is valid
  • Commits include DCO sign-off
  • No Python fallback code (Rust-only operation)
  • Clear error messages for missing Rust module

Related Issues

Closes #[issue-number]

Original Implementation

The complete implementation was originally added to mcp-context-forge in:

  • PR: #3728
  • Commit: 8bb308c50fb882172131411d6854d789c27273ec
  • Date: March 22, 2026
  • Authors: @cafalchio, @criveti

Additional Notes

This PR ensures the url_reputation plugin is fully functional and provides the high-performance Rust-based URL validation that was originally designed. The plugin is now ready for production use in the cpex-plugins ecosystem.

Suresh Kumar Moharajan added 2 commits April 20, 2026 13:16
…plugin

The url_reputation plugin was missing its complete Rust implementation
after migration from mcp-context-forge. This commit recovers all missing
Rust source files from git history (commit 8bb308c50).

Recovered files:
- src/engine.rs (707 lines) - Core validation engine
- src/types.rs (79 lines) - Type definitions and PyO3 bindings
- src/filters/ - Heuristic, IANA TLD, and pattern filters
- benches/url_validation.rs - Performance benchmarks
- Enhanced test suite and documentation

The plugin now has complete functionality including:
- URL reputation validation with configurable policies
- Heuristic entropy-based checks
- IANA TLD validation
- Pattern-based allow/block lists
- Domain whitelist/blocklist support
- HTTP/HTTPS scheme enforcement

Updated Cargo.toml with required dependencies:
- idna, url, regex for URL parsing and validation
- phf for efficient TLD lookups
- unicode-script, unicode-security for domain validation
- criterion for benchmarking

Fixed test imports to use cpex_url_reputation module path.
Added _RUST_AVAILABLE flag for Python fallback detection.

Build verification:
- All 24 Rust unit tests pass
- 30 out of 32 Python tests pass (2 pre-existing test issues)
- Plugin compiles and installs successfully

Signed-off-by: Suresh Kumar Moharajan <suresh.kumar.m@ibm.com>
The url_reputation plugin now requires the Rust implementation and will
raise a clear error if the Rust module is not available, rather than
falling back to a limited Python implementation.

Changes:
- Modified URLReputationPlugin.__init__ to raise RuntimeError if Rust
  module is not available
- Removed all Python fallback tests (test_python_* functions)
- Removed Rust error fallback test (test_rust_error_fallback_blocks_url)
- Plugin now enforces Rust-only operation for consistency and performance

Test results:
- 22 tests passed
- 9 tests skipped (Rust-specific features)
- 0 tests failed

This ensures users get the full Rust-powered functionality or a clear
error message to install the plugin properly with 'make install'.

Signed-off-by: Suresh Kumar Moharajan <suresh.kumar.m@ibm.com>
@lucarlig lucarlig merged commit 9314b5c into main Apr 20, 2026
30 checks passed
@lucarlig lucarlig deleted the recover-url-reputation-rust-implementation branch April 20, 2026 13:10
lucarlig pushed a commit that referenced this pull request Apr 20, 2026
… plugin (#38)

* fix(plugins): recover missing Rust implementation for url_reputation plugin

The url_reputation plugin was missing its complete Rust implementation
after migration from mcp-context-forge. This commit recovers all missing
Rust source files from git history (commit 8bb308c50).

Recovered files:
- src/engine.rs (707 lines) - Core validation engine
- src/types.rs (79 lines) - Type definitions and PyO3 bindings
- src/filters/ - Heuristic, IANA TLD, and pattern filters
- benches/url_validation.rs - Performance benchmarks
- Enhanced test suite and documentation

The plugin now has complete functionality including:
- URL reputation validation with configurable policies
- Heuristic entropy-based checks
- IANA TLD validation
- Pattern-based allow/block lists
- Domain whitelist/blocklist support
- HTTP/HTTPS scheme enforcement

Updated Cargo.toml with required dependencies:
- idna, url, regex for URL parsing and validation
- phf for efficient TLD lookups
- unicode-script, unicode-security for domain validation
- criterion for benchmarking

Fixed test imports to use cpex_url_reputation module path.
Added _RUST_AVAILABLE flag for Python fallback detection.

Build verification:
- All 24 Rust unit tests pass
- 30 out of 32 Python tests pass (2 pre-existing test issues)
- Plugin compiles and installs successfully

Signed-off-by: Suresh Kumar Moharajan <suresh.kumar.m@ibm.com>

* fix(plugins): remove Python fallback logic from url_reputation plugin

The url_reputation plugin now requires the Rust implementation and will
raise a clear error if the Rust module is not available, rather than
falling back to a limited Python implementation.

Changes:
- Modified URLReputationPlugin.__init__ to raise RuntimeError if Rust
  module is not available
- Removed all Python fallback tests (test_python_* functions)
- Removed Rust error fallback test (test_rust_error_fallback_blocks_url)
- Plugin now enforces Rust-only operation for consistency and performance

Test results:
- 22 tests passed
- 9 tests skipped (Rust-specific features)
- 0 tests failed

This ensures users get the full Rust-powered functionality or a clear
error message to install the plugin properly with 'make install'.

Signed-off-by: Suresh Kumar Moharajan <suresh.kumar.m@ibm.com>

---------

Signed-off-by: Suresh Kumar Moharajan <suresh.kumar.m@ibm.com>
Co-authored-by: Suresh Kumar Moharajan <suresh.kumar.m@ibm.com>
Signed-off-by: lucarlig <luca.carlig@ibm.com>
@msureshkumar88
Copy link
Copy Markdown
Collaborator Author

Linked to #20

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.

[BUG] url_reputation plugin missing complete Rust implementation

2 participants