Skip to content

[Build] Block insecure HTTP Maven repository URLs for defense in depth#11351

Merged
simonrozsival merged 4 commits into
mainfrom
jonathanpeppers/maven-require-allowinsecurehttp
May 16, 2026
Merged

[Build] Block insecure HTTP Maven repository URLs for defense in depth#11351
simonrozsival merged 4 commits into
mainfrom
jonathanpeppers/maven-require-allowinsecurehttp

Conversation

@jonathanpeppers
Copy link
Copy Markdown
Member

@jonathanpeppers jonathanpeppers commented May 14, 2026

Summary

Aligning with Gradle & Maven behavior for defense in depth and supply-chain hardening.

When a customer specifies an http:// Maven repository URL, the build now fails with error XA4252 unless AllowInsecureHttp="true" metadata is explicitly set on the item. HTTPS URLs are unaffected.

Problem

A customer could write an insecure http:// Maven repository URL and the product would use it.

Solution

Require explicit opt-in via AllowInsecureHttp="true" metadata:

<!-- This will now fail with XA4252 -->
<AndroidMavenLibrary Include="com.example:library" Version="1.0.0" Repository="http://repo.example.com/maven2/" />

<!-- Explicit opt-in to insecure HTTP -->
<AndroidMavenLibrary Include="com.example:library" Version="1.0.0" Repository="http://repo.example.com/maven2/" AllowInsecureHttp="true" />

This mirrors what Gradle (allowInsecureProtocol) and Maven (<blocked>http://*</blocked>) already enforce by default.

Changes

  • MavenDownload.cs — Added HTTP check in GetRepository() that logs error XA4252 when http:// is used without AllowInsecureHttp="true"
  • Resources.resx / Resources.Designer.cs — Added XA4252 error message
  • MavenDownloadTests.cs — Two new tests:
    • InsecureHttpRepository_Blocked — verifies http:// URL without opt-in produces XA4252
    • InsecureHttpRepository_AllowedWithOptIn — verifies AllowInsecureHttp="true" bypasses the check

jonathanpeppers and others added 3 commits May 14, 2026 15:46
… set

When a `<AndroidMavenLibrary>` item specifies an `http://` repository URL,
the build now fails with error XA4251 unless `AllowInsecureHttp="true"`
metadata is explicitly set on the item. HTTPS URLs are unaffected.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
XA4251 was taken by main for JniAddNativeMethodRegistrationAttribute.
Renumbered the insecure HTTP Maven error to XA4252.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jonathanpeppers jonathanpeppers marked this pull request as ready for review May 15, 2026 13:23
Copilot AI review requested due to automatic review settings May 15, 2026 13:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens Maven dependency restore by rejecting insecure HTTP Maven repository URLs unless an explicit item metadata opt-in is provided.

Changes:

  • Adds XA4252 validation for insecure HTTP repositories in MavenDownload.
  • Adds localized resource entries for the new error.
  • Adds unit tests for blocked and opt-in HTTP repository behavior.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/Xamarin.Android.Build.Tasks/Tasks/MavenDownload.cs Adds HTTP repository validation and XA4252 logging.
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/MavenDownloadTests.cs Adds tests for blocked and allowed insecure HTTP repositories.
src/Xamarin.Android.Build.Tasks/Properties/Resources.resx Adds the XA4252 error message resource.
src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs Adds the generated accessor for XA4252.
Files not reviewed (1)
  • src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs: Language not supported

Comment thread src/Xamarin.Android.Build.Tasks/Tasks/MavenDownload.cs Outdated
Comment thread src/Xamarin.Android.Build.Tasks/Properties/Resources.resx
- Use Uri.TryCreate + scheme check instead of string prefix matching
  to properly handle all HTTP URI variations (defense in depth).
- Make opt-in test assertion positive: assert XA4236 download error
  instead of just checking absence of XA4252.
- Add XA4252 error documentation (xa4252.md) and update message index.
- Document AllowInsecureHttp metadata in both build-items.md files.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jonathanpeppers jonathanpeppers added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label May 15, 2026
@simonrozsival simonrozsival merged commit 0e0163f into main May 16, 2026
3 checks passed
@simonrozsival simonrozsival deleted the jonathanpeppers/maven-require-allowinsecurehttp branch May 16, 2026 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants