Keywords: Maven | HTTP blocking | mirror configuration | security vulnerability | build error
Abstract: This article provides an in-depth analysis of the default HTTP mirror blocking mechanism introduced in Maven 3.8.1 to address the CVE-2021-26291 security vulnerability. It explains why developers may encounter "Blocked mirror for repositories" errors even with custom mirror configurations and presents three practical solutions: modifying global configuration files, overriding settings in user configuration, or downgrading Maven versions. Each solution includes detailed configuration examples and security considerations to help developers choose the most appropriate approach for their specific needs.
Problem Context and Error Symptoms
During Maven project development, developers may encounter "Blocked mirror for repositories" errors even after configuring mirrors in settings files. This typically occurs when dependencies are fetched from repositories using HTTP protocol. The error indicates that Maven is blocking access to insecure HTTP repositories, which can cause build failures.
Security Enhancement in Maven 3.8.1
Maven 3.8.1 introduced a significant security enhancement specifically targeting the CVE-2021-26291 vulnerability. This vulnerability involves potential man-in-the-middle attacks when downloading dependencies over HTTP. Since POM files in Maven Central may contain references to HTTP repositories that cannot be modified after upload, the Maven team decided to address this issue at the framework level.
The core of the new mechanism extends mirror configuration functionality by adding the <blocked> parameter and introducing the external:http:* mirror selector. This selector matches all external repository URLs using HTTP protocol. By default, Maven blocks access to such insecure HTTP external repositories through predefined mirror configurations.
How the Default Blocking Mechanism Works
Maven includes configuration files in two locations upon installation:
- Maven installation directory: ${maven.home}/conf/settings.xml
- User configuration directory: ${user.home}/.m2/settings.xml
The global configuration file contains the following default mirror configuration:
<mirror>
<id>maven-default-http-blocker</id>
<mirrorOf>external:http:*</mirrorOf>
<name>Pseudo repository to mirror external repositories initially using HTTP.</name>
<url>http://0.0.0.0/</url>
<blocked>true</blocked>
</mirror>
This configuration intercepts all repository requests matching the external:http:* pattern, redirecting them to an invalid address while marking them as blocked. This explains why developers may still encounter build errors even after adding custom mirror configurations—the default blocker takes precedence over user-defined mirrors.
Solution 1: Modify Global Configuration File
The most direct solution is to modify the global configuration file in the Maven installation directory. Developers can locate and edit /usr/share/maven/conf/settings.xml, then comment out or completely remove the default HTTP blocking mirror:
<!--
<mirror>
<id>maven-default-http-blocker</id>
<mirrorOf>external:http:*</mirrorOf>
<name>Pseudo repository to mirror external repositories initially using HTTP.</name>
<url>http://0.0.0.0/</url>
<blocked>true</blocked>
</mirror>
-->
It's important to note that while this method is simple and effective, it reduces project security since all HTTP repositories will no longer be blocked. The Maven official documentation explicitly warns about the security risks of this approach.
Solution 2: Override Default Settings in User Configuration
To avoid modifying global configuration files, developers can add a mirror configuration with the same ID in the user-level settings.xml file to override default settings. This method doesn't affect other users or projects and offers greater flexibility and security.
Add the following configuration to the <mirrors> section in ${user.home}/.m2/settings.xml:
<mirror>
<id>maven-default-http-blocker</id>
<url>http://127.0.0.1/dont-go-here</url>
<mirrorOf>dummy</mirrorOf>
<blocked>false</blocked>
</mirror>
The key aspects of this configuration are:
- Using the same ID (maven-default-http-blocker) to override default configuration
- Setting mirrorOf to dummy so it only matches non-existent repository patterns
- Setting blocked to false to disable blocking functionality
- Pointing URL to a local invalid address to ensure it's never actually used
Another overriding approach modifies the mirror selector:
<mirror>
<id>maven-default-http-blocker</id>
<mirrorOf>external:dummy:*</mirrorOf>
<name>Pseudo repository to mirror external repositories initially using HTTP.</name>
<url>http://0.0.0.0/</url>
<blocked>true</blocked>
</mirror>
This method changes mirrorOf from external:http:* to external:dummy:*, causing the default blocker to only match the non-existent dummy protocol, thereby bypassing HTTP repository blocking.
Solution 3: Downgrade Maven Version
If projects cannot immediately adapt to the new security mechanism, consider downgrading to Maven 3.6 or earlier versions. These versions don't include the default HTTP blocking mechanism, so "Blocked mirror for repositories" errors won't occur.
Example downgrade command (using Homebrew):
brew uninstall maven
brew install maven@3.6
Note that downgrading loses all security enhancements introduced in Maven 3.8.1, including fixes for the CVE-2021-26291 vulnerability. Therefore, this should be considered a temporary solution, with one of the first two methods preferred for long-term use.
Security Considerations and Best Practices
While disabling HTTP blocking can resolve build issues, developers must be aware of associated security risks:
- Data transmitted over HTTP may be intercepted or modified by man-in-the-middle attacks
- Malicious actors could inject harmful code into dependencies
- Sensitive information (such as authentication credentials) might be exposed
Best practice recommendations:
- Prefer repositories using HTTPS protocol
- If HTTP repositories must be used, ensure network environment security
- Regularly update dependencies and check security advisories
- Utilize dependency vulnerability scanning tools
- Consider setting up private mirror repositories for centralized dependency management
Conclusion
The default HTTP mirror blocking mechanism introduced in Maven 3.8.1 represents an important security enhancement designed to protect developers from man-in-the-middle attacks. When encountering "Blocked mirror for repositories" errors, developers have three main solutions: modifying global configuration, overriding settings in user configuration, or downgrading Maven versions. Each approach has its advantages and disadvantages, and developers should choose based on project requirements and security considerations. Long-term migration to HTTPS repositories remains the most secure and reliable solution.