Skip to content

Fix #13084: sandbox profile activation context for external model builds - #13112

Merged
gnodet merged 8 commits into
apache:masterfrom
gnodet:fix/13084-sandbox-external-profile-activation
Sep 16, 2026
Merged

gnodet merged 8 commits into
apache:masterfrom
gnodet:fix/13084-sandbox-external-profile-activation

Conversation

@gnodet

@gnodet gnodet commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Problem

The fix in f599020 blocked file- and property-activated profiles in external (repository-resolved) model builds by pre-filtering the profile list before activation. This correctly stopped consumer -D flags from activating dependency profiles, but had a correctness gap:

  • It blocked all property-activated profiles, including those conditioned on the model's own <properties> section — which are part of the artifact's published identity, not the consumer's build environment.
  • #13095 partially addressed this by allowing negated-property profiles (!foo), but missed the symmetric case: a publisher who declares <properties><foo>bar</foo></properties> and conditions a profile on <property><name>foo</name></property> would still be broken.

Solution

Replace the type-based profile pre-filter with a sandboxed ProfileActivationContext for external model builds. All profiles are passed to the selector; the sandbox restricts what inputs they see:

Input External model Rationale
System properties (java.version, os.name, …) ✅ Preserved Platform facts — JDK/OS activation must work
Model <properties> ✅ Preserved Part of the artifact's published identity
User properties (-D flags) ❌ Emptied Consumer didn't set these for the dependency
File existence ❌ Disabled Publisher paths don't exist on the consumer's machine

This gives correct results in all cases:

  • <property><name>foo</name></property> where foo=bar in <properties> → fires ✅
  • <property><name>!foo</name></property> (absent from sandbox) → fires ✅ (default-on preserved)
  • <property><name>flag</name></property> where flag is only in consumer -D → suppressed ✅
  • <jdk>, <os>, activeByDefault → always fire ✅
  • File activation → suppressed ✅

Changes

Both stacks (compat maven-model-builder and new impl/maven-impl):

  • DefaultModelBuilder: replace pre-filter with sandboxed context for the externalOrigin / VALIDATION_LEVEL_MINIMAL branch
  • PropertyProfileActivator: add model/project <properties> as third fallback in lookup chain (user → system → model)
  • DefaultProfileActivationContext (new stack): add withoutUserPropertiesAndFilesystem() returning a sandboxed context view
  • ProfileActivationContext interfaces: updated Javadoc on getUserProperties()/getUserProperty() and getProjectProperties()/getModelProperty() to document the external-model contract

Tests: ExternalModelProfileActivationTest rewritten with 8 focused cases covering each activation type separately.

Supersedes

Supersedes #13095 (which is a narrower workaround for the negated-property case only). Fixes #13084.

…el builds

Replace the type-based profile pre-filter with a sandboxed ProfileActivationContext
for repository-resolved (external) models — dependency POMs, parent POMs, imported BOMs.

## Problem

The original fix (f599020) blocked file- and property-activated profiles in external
model builds by pre-filtering the profile list. This correctly stopped consumer -D flags
from activating dependency profiles, but had two flaws:

1. It also blocked profiles conditioned on the POM's own <properties> section, which are
   part of the artifact's published identity (not the consumer's environment).
2. apache#13095 worked around flaw (1) for the negated-property case (!foo) only, but missed
   the positive case where a publisher declares <properties><foo>bar</foo></properties>
   and conditions a profile on <property><name>foo</name></property>.

## Solution

Instead of filtering profiles by activation type, pass all profiles to the selector but
evaluate them against a sandboxed ProfileActivationContext that:

- **Preserves system properties** (java.version, os.name, …) so JDK/OS activation works.
- **Preserves model properties** (the POM's own <properties>) because they are part of
  the artifact's published identity, not the consumer's environment.
- **Empties user properties** so consumer -D flags cannot activate dependency profiles.
- **Disables file existence checks** (new stack: exists() returns false; legacy: file
  profiles are pre-filtered as before) because publisher paths don't exist in the
  consumer's environment.

This is applied consistently in both the legacy compat stack (DefaultModelBuilder in
maven-model-builder) and the new Maven 4 stack (DefaultModelBuilder in maven-impl).

## PropertyProfileActivator

Both stacks' PropertyProfileActivator now consult model/project properties as a third
fallback (after user → system), making POM-declared-property activation work correctly
in all contexts including external model builds.

## Documentation

Javadoc updated on ProfileActivationContext.getUserProperties() / getUserProperty()
and getProjectProperties() / getModelProperty() to explain the external-model contract.

## Tests

ExternalModelProfileActivationTest rewritten with 8 targeted cases covering:
- File activation suppressed
- User-property (-D) activation suppressed
- System-property activation preserved
- POM-declared-property activation preserved (the key new case)
- Negated-property default-on activation preserved
- JDK activation preserved
- Profile repositories always stripped

Supersedes apache#13095. Fixes apache#13084.

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Solid approach. The sandbox pattern is a clear improvement over the type-based pre-filter — it correctly activates POM-declared property profiles while still suppressing consumer -D injection. Two findings below.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

some.gating.property and some.condition.property simulate -D flags in tests.
With the sandbox approach, system properties survive the external-model context
(they are platform facts like java.version), so these must be in userProperties
to be correctly suppressed in external model builds.

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-review after c639b4f (fix tests: move simulated -D flags from system to user properties).

The new commit correctly moves some.gating.property and some.condition.property from system to user properties in DefaultModelBuilderTest, so the external-model sandbox actually exercises its suppression logic. The test was previously passing for the wrong reason (gating props in system properties survived the sandbox). Good catch.

Two findings from the previous review remain unaddressed — re-raising below.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

- Fix compat PropertyProfileActivator comment referencing
  getExternalActivationContext() → externalActivationContext()
- Pre-filter file-activated profiles in impl stack for external models,
  matching compat stack behavior: returning false from exists() alone
  would incorrectly activate <missing> profiles
- Update Javadoc in DefaultProfileActivationContext to document the
  pre-filtering requirement

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-review after 8ff7ca6e23 — both previous findings addressed.

  1. Javadoc method name (getExternalActivationContext() → externalActivationContext()): fixed in the compat PropertyProfileActivator comment.
  2. <file><missing> behavioral asymmetry: the impl stack now pre-filters file-activated profiles before evaluation, matching the compat stack's withoutFileActivation() approach. Both stacks are now consistent.

The sandbox approach is solid. Condition-activated profiles (impl stack) are no longer blanket-filtered but evaluated against the sandboxed context — this is strictly more correct since the sandbox naturally suppresses user-property references without losing condition expressions that depend only on system/model properties.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

The PropertyProfileActivator was unconditionally checking model/project
properties (getModelProperty/getProjectProperties) for ALL profile
evaluations, including the build's own project.  This caused unintended
profile activation when a POM declares a property that matches a
profile's activation condition — e.g. the IT proxy profile activating
because <proxy.host>localhost</proxy.host> was declared in <properties>.

Fix: revert the model property fallback in PropertyProfileActivator and
instead merge model properties into the system properties map within
the sandboxed context used for external (dependency/parent/BOM) model
builds.  This ensures POM-declared properties drive profile activation
only in external builds (where they represent the artifact's published
identity), not in the build's own project (where they could conflict
with activation conditions).

Also use fully-qualified plugin coordinate in MNG-8736 IT to avoid
NoPluginFoundForPrefixException in the restricted IT environment.

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-review after f2bf110b0a — model property lookup moved from activator to sandbox context.

Good refactor. The previous approach (adding getProjectProperties() / getModelProperty() as a third fallback in PropertyProfileActivator) had the side effect of making POM-declared-property profiles fire in ALL builds, including the build's own project. This commit fixes that by merging model properties into the system properties map inside the sandbox only — so the activator's lookup chain stays unchanged for non-external models, and POM-declared properties only drive activation in external (dependency/parent/BOM) builds where they belong.

Both stacks are consistent:

  • Compat sandbox: getSystemProperties() merges project props into a new HashMap (system wins via putAll ordering)
  • Impl sandbox: getSystemProperty(key) falls back to getModelProperty(key) per-key

Test updated correctly — assertNull for POM-declared-property profile in project builds, assertEquals("activated") in external builds.

The IT change (help:active-profiles → fully qualified maven-help-plugin:3.5.1:active-profiles) is a valid stability fix.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

@gnodet gnodet added this to the 4.1.0 milestone Sep 14, 2026
@gnodet gnodet added bug Something isn't working backport-to-4.0.x labels Sep 14, 2026
@gnodet
gnodet requested review from ascheman and cstamas September 15, 2026 12:46
gnodet added a commit to gnodet/maven that referenced this pull request Sep 15, 2026
…el builds

Backport of apache#13112 to `maven-3.10.x`.

Cherry-picked and manually adapted from the master commits:
- e58a96a Fix apache#13084: sandbox profile activation context for external model builds
- 8ff7ca6 Address review: fix Javadoc method ref and file-activation asymmetry
- f2bf110 fix: move model property lookup from activator to sandbox context

The second commit (c639b4f) was empty on this branch (it only touched
impl/maven-impl/ which doesn't exist on maven-3.10.x; the equivalent
adjustment was already included in the first commit's ResolvedDependencyProfileActivationTest).

Conflicts resolved by adapting to the flat module layout of maven-3.10.x:
- Changes to compat/maven-model-builder/ cherry-picked cleanly as maven-model-builder/
- Changes to impl/maven-impl/ have no direct equivalent (not removed — confirmed n/a)
- Changes to its/core-it-suite/ removed (ITs are in a separate repo on this branch)
gnodet added a commit to gnodet/maven that referenced this pull request Sep 16, 2026
…efault-on profile

Port test coverage gap flagged in gnodet-bot re-review:
- Add testExternalModelSystemPropertySuppressesDefaultOnProfile: verifies
  that a consumer setting skip.defaults as a *system* property suppresses
  the dependency's default-on (!skip.defaults) profile in external builds.
  System properties pass through the sandbox unchanged; this is intentional
  behavior but was unprotected by a test.

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-review after b1506fc1 — prior findings addressed; one new gap.

The new commit correctly reconciles with #13114: the !skip.defaults negated-property profile is wired into the impl fixture and tests, and the system-property-suppresses-default-on case is now covered in DefaultModelBuilderTest. One parallel-path asymmetry: the equivalent system-property-suppression test is missing from the compat stack.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

…proach

Conflicts resolved:
- impl/maven-impl/.../DefaultModelBuilder.java: keep sandbox activation
  (withoutUserPropertiesAndFilesystem) but drop repo stripping per apache#13100.
  Repositories from legitimately-active external profiles (JDK/OS/activeByDefault
  and POM-property-gated) are now honored, fixing the dep1→dep2 repo pattern.
- compat/.../ExternalModelProfileActivationTest.java: keep comprehensive sandbox
  tests (file, user-prop, sys-prop, POM-declared, negated, JDK), update repo
  assertion from noneMatch→anyMatch, add testActiveByDefaultProfileRepositoryHonored
  from apache#13100.
…efault-on profile

Port test coverage gap from the apache#13114 review:
- Add negated-property-default-on profile to the XML fixture
- Assert it fires in project builds (skip.defaults absent from system props)
- Add testExternalModelSystemPropertySuppressesDefaultOnProfile: verifies
  that a consumer setting skip.defaults as a *system* property suppresses
  the dependency's default-on profile (system props pass through the sandbox)
@gnodet
gnodet force-pushed the fix/13084-sandbox-external-profile-activation branch from b1506fc to 48bdea0 Compare September 16, 2026 13:46
@gnodet

gnodet commented Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

Conflict resolved with origin/master (which includes #13100).

The two PRs are complementary — not contradictory. Merged approach:

  • Sandbox kept (withoutUserPropertiesAndFilesystem()): user-property suppression + POM-declared property activation remain intact.
  • Repo stripping removed (per [3.10] Questions to discuss #13100): repositories from legitimately-active external profiles (JDK/OS/activeByDefault and POM-property-gated) are now honored, fixing the project → dep1 → dep2 pattern.
  • Test reconciliation: testExternalModelProfileRepositoriesAreAlwaysStripped renamed to testExternalModelJdkProfileRepositoriesAreHonored with noneMatch → anyMatch; testActiveByDefaultProfileRepositoryHonored added from [3.10] Questions to discuss #13100; negated-property default-on assertions added to DefaultModelBuilderTest from b1506fc.

All 50 tests pass (40 impl + 9 compat ExternalModelProfileActivationTest + 1 compat DefaultModelBuilderTest).

Add testExternalModelSystemPropertySuppressesDefaultOnProfile to
ExternalModelProfileActivationTest to mirror the equivalent test in
DefaultModelBuilderTest (impl stack). Verifies that a system property
named 'skip.defaults' suppresses the default-on negated-property profile
(!skip.defaults) in external builds — system properties are platform
facts that pass through the sandbox unchanged.

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-review after 48bdea09 — previous finding partially addressed; compat test gap remains.

The new commit correctly adds testExternalModelSystemPropertySuppressesDefaultOnProfile to the impl stack (DefaultModelBuilderTest) and wires up the negated-property-default-on profile in the XML fixture. One gap carries over.


Previous finding (NOT addressed): compat stack missing system-property-suppresses-default-on test

The impl stack now asserts that setting skip.defaults as a system property suppresses the default-on !skip.defaults profile even in external builds (testExternalModelSystemPropertySuppressesDefaultOnProfile). The equivalent test is absent from ExternalModelProfileActivationTest (compat stack).

The compat externalActivationContext() merges model properties into system properties and suppresses user properties — the same sandbox logic as the impl stack. Without this test, a regression in externalActivationContext() that accidentally lets system properties through (or accidentally clears them) would go undetected on the compat path.

Missing test to add to compat/maven-model-builder/src/test/java/org/apache/maven/model/building/ExternalModelProfileActivationTest.java:

@Test
void testExternalModelSystemPropertySuppressesDefaultOnProfile() throws Exception {
    // A system property named skip.defaults suppresses the default-on negated-property
    // profile (!skip.defaults) even in external model builds: system properties are
    // platform facts that pass through the sandbox unchanged.
    Properties sp = systemPropertiesWithTestValues();
    sp.setProperty("skip.defaults", "true"); // system-level opt-out
    Model model = build(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL, sp, new Properties());

    assertNull(
            model.getProperties().get("profile.negated.property"),
            "negated-property (default-on) profile must be suppressed when system property 'skip.defaults' is set");
}

New (low): getSystemProperties() allocates a new HashMap on every call in the compat sandbox

In externalActivationContext() (compat DefaultModelBuilder), getSystemProperties() creates a fresh HashMap each time it is called. PropertyProfileActivator.isActive() calls it once per profile being evaluated — for a POM with many property-activated profiles this adds unnecessary allocations. The impl stack avoids this via scalar getSystemProperty(key) with a direct fallback to getModelProperty(key) (no map copy needed).

Consider caching the merged map in the anonymous class (computed once on first access via a field initialized lazily in the constructor or via Suppliers.memoize), or — better — following the impl's pattern of using the scalar getSystemProperty(String) method with a fallback, which the compat ProfileActivationContext interface also exposes.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

cstamas pushed a commit that referenced this pull request Sep 16, 2026
…model builds (#13114)

Backport of #13112 to `maven-3.10.x`.

Cherry-picked and manually adapted from the master commits:
- e58a96a Fix #13084: sandbox profile activation context for external model builds
- 8ff7ca6 Address review: fix Javadoc method ref and file-activation asymmetry
- f2bf110 fix: move model property lookup from activator to sandbox context

Conflicts resolved by adapting to the flat module layout of maven-3.10.x:
- `compat/maven-model-builder/` → `maven-model-builder/` (flat layout)
- `impl/maven-impl/` changes have no equivalent on 3.10.x (not present)
- `its/core-it-suite/` changes dropped (ITs are in a separate repo on this branch)

See #13112 for the full rationale and design.
…ndbox

Avoid creating a new HashMap on every getSystemProperties() call in the
anonymous ProfileActivationContext returned by externalActivationContext().
The merged map is now computed once on first access and cached in a field.
This matches the intent of the impl stack which uses a scalar per-key lookup
(getSystemProperty → getModelProperty) without any map copy.

Addresses low-priority finding from code review.
@gnodet

gnodet commented Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the low-priority finding from the last review: caching the merged system+project properties map in externalActivationContext() (compat stack) to avoid a new HashMap allocation per getSystemProperties() call. Fixed in 3639a89689.

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-review after 95fefaf7e7 + 3639a89689 — both outstanding findings addressed.

  1. Compat stack system-property suppression test (testExternalModelSystemPropertySuppressesDefaultOnProfile in ExternalModelProfileActivationTest): added, mirrors the impl stack test exactly. ✅

  2. getSystemProperties() allocation per call (low, compat sandbox): fixed by adding a mergedSystemProperties cache field to the anonymous ProfileActivationContext. The cache is correctly scoped per anonymous instance — a new instance is created per loop iteration (model in parent chain), and setProjectProperties() mutates the delegate between iterations so each iteration needs its own merged map. No stale-cache risk. ✅

Both stacks are now consistent in behaviour and test coverage. The sandbox approach is solid.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

@gnodet
gnodet merged commit 9f5f92f into apache:master Sep 16, 2026
20 checks passed
@gnodet
gnodet deleted the fix/13084-sandbox-external-profile-activation branch September 16, 2026 18:48
gnodet added a commit to gnodet/maven that referenced this pull request Sep 16, 2026
…el builds

Backport of apache#13112 (master) and apache#13114 (maven-3.10.x) to maven-4.0.x.

Instead of blanket-filtering file and property profiles in external model
builds (dependency POMs, parent POMs, imported BOMs), evaluate them against
a sandboxed ProfileActivationContext that:

 - Merges model properties into system property lookups (so POM-declared
   <properties> drive property-activated profiles in dependency builds).
 - Suppresses user properties (consumer -D flags must not activate
   dependency profiles — they were not set for that artifact).
 - Pre-filters file-activated profiles (returning false from exists() would
   incorrectly activate <missing> profiles).
 - Strips repository contributions from all active external profiles.

Both compat and impl stacks are updated identically. The key insight is that
model properties are merged into system properties inside the sandbox rather
than changing PropertyProfileActivator's lookup chain, to avoid unintended
activation when a project POM declares a property that coincidentally matches
a profile's activation condition.

Tests: ExternalModelProfileActivationTest (compat) and DefaultModelBuilderTest
(impl) cover file suppression, user-property suppression, system-property
preservation, POM-declared-property activation, negated-property default-on
preservation, and system-property opt-out of the default-on pattern.
gnodet added a commit that referenced this pull request Sep 17, 2026
…lds (#13158)

* Fix #13084: sandbox profile activation context for external model builds

Backport of #13112 (master) and #13114 (maven-3.10.x) to maven-4.0.x.

Instead of blanket-filtering file and property profiles in external model
builds (dependency POMs, parent POMs, imported BOMs), evaluate them against
a sandboxed ProfileActivationContext that:

 - Merges model properties into system property lookups (so POM-declared
   <properties> drive property-activated profiles in dependency builds).
 - Suppresses user properties (consumer -D flags must not activate
   dependency profiles — they were not set for that artifact).
 - Pre-filters file-activated profiles (returning false from exists() would
   incorrectly activate <missing> profiles).
 - Strips repository contributions from all active external profiles.

Both compat and impl stacks are updated identically. The key insight is that
model properties are merged into system properties inside the sandbox rather
than changing PropertyProfileActivator's lookup chain, to avoid unintended
activation when a project POM declares a property that coincidentally matches
a profile's activation condition.

Tests: ExternalModelProfileActivationTest (compat) and DefaultModelBuilderTest
(impl) cover file suppression, user-property suppression, system-property
preservation, POM-declared-property activation, negated-property default-on
preservation, and system-property opt-out of the default-on pattern.

* Address review: fix mutable map leak in compat sandbox context, pre-filter missing()-condition profiles in CONSUMER_DEPENDENCY builds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3.10.x fails on org.jboss.resteasy:resteasy-client:jar:7.0.0.Final

3 participants