8000 solve : Invalid URL Handling in Plugin Scanning Results in http.client.InvalidURL Error · Issue #40 · dionach/CMSmap · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
solve : Invalid URL Handling in Plugin Scanning Results in http.client.InvalidURL Error #40
Open
@Slimaissaoui

Description

@Slimaissaoui

Environment:
OS: Kali Linux
Python Version: 3.13
CMSmap Version: Latest version (as of March 2025)

Summary:
When CMSmap attempts to scan plugins with names containing spaces or special characters (such as parentheses, quotes, etc.), it throws an http.client.InvalidURL error. This prevents the tool from successfully completing a scan, causing it to crash prematurely.


Background:
CMSmap is a popular tool for testing CMS (Content Management Systems) for vulnerabilities. One of its features includes scanning plugins for potential security issues. During this process, the tool constructs URLs dynamically by concatenating the base URL, the plugin path, the plugin name, and additional paths. However, if the plugin name includes spaces or special characters, the URL generated is not valid, leading to the following error:

http.client.InvalidURL: URL can't contain control characters. '/wp-content/plugins/worprees plugin bug dar/' (found at least ' ')

The error occurs because CMSmap is trying to pass a plugin name with invalid characters in the URL, which results in a failed request.

Root Cause:
The root cause of the error is CMSmap’s failure to properly encode the plugin name when constructing URLs. URLs cannot contain control characters like spaces, parentheses, or quotes directly. Instead, these characters must be percent-encoded (URL-encoded) to ensure valid HTTP requests.


Proposed Solution:

< 6539 p dir="auto">Fix 1: URL-Encoding Plugin Names

The solution involves applying URL-encoding to the plugin name when constructing the URL. The urllib.parse.quote() function should be used to safely encode any special characters or spaces in the plugin name.

Code Changes:

Modify the ThreadScanner class in threadscanner.py to encode the plugin name when constructing the URL.

import urllib.parse

Encode plugin name for valid URL

encoded_plugin = urllib.parse.quote(plugin)

Construct the URL safely using the encoded plugin name

full_url = self.url + self.pluginPath + encoded_plugin + self.pluginPathEnd
requester.request(full_url, data=None)

How This Fix Solves the Problem:
By URL-encoding the plugin name, any spaces or special characters are converted into their respective ASCII codes (e.g., a space becomes %20), which ensures that the generated URLs are valid and can be processed correctly by the HTTP client.

Edge Cases Considered:

  • Special characters like &, (, ), #, etc., will all be safely encoded.
  • Plugins with spaces or multiple special characters in their names will no longer cause crashes.

Testing the Fix:

After implementing the fix, the following tests should be performed to ensure the bug is resolved:

Test Cases:

  1. Valid Plugin Names:

    • Plugins with names like backup-backup should work without issues.

    Expected Result: CMSmap should successfully detect the plugin without any errors.

  2. Plugin Names with Spaces:

    • Plugins with names like backup backup should be URL-encoded and scanned.

    Expected Result: The plugin name should be encoded as backup%20backup, and CMSmap should continue scanning without throwing the InvalidURL error.

  3. Plugin Names with Special Characters:

    • Plugins with names like backup(backup) or backup&backup should also be encoded and scanned.

    Expected Result: Special characters should be encoded and scanning should continue normally.

Result:

  • The InvalidURL error is no longer triggered when scanning plugins with special characters or spaces.
  • CMSmap completes the scan successfully.

Additional Considerations:

Future Improvements:

  1. Improved Error Handling: CMSmap can be enhanced to handle invalid plugin names more gracefully by catching InvalidURL exceptions and reporting them to the user, rather than crashing.
  2. Input Validation: Validate plugin names before attempting to construct the URL. This will allow CMSmap to handle poorly named plugins more efficiently.

Conclusion:

By URL-encoding plugin names during URL construction, the issue with http.client.InvalidURL has been resolved. This fix ensures that plugins with spaces or special characters are processed correctly, allowing CMSmap to continue scanning without interruptions.

Image
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0