Skip to content

[ISSUE #11544] fix(auth): guard against null environment in Environment#isMatch - #11545

Open
leaveWhite9088 wants to merge 2 commits into
apache:developfrom
leaveWhite9088:fix/auth-environment-null-check
Open

leaveWhite9088 wants to merge 2 commits into
apache:developfrom
leaveWhite9088:fix/auth-environment-null-check

Conversation

@leaveWhite9088

Copy link
Copy Markdown
Contributor

Which Issue(s) This PR Fixes

Brief Description

When an ACL PolicyEntry defines a source IP restriction and DefaultAuthorizationContext#getSourceIp() is null or empty (for example, when a Netty channel has no remote address or a non-TCP gRPC transport omits GrpcConstants.REMOTE_ADDRESS), Environment.of(context.getSourceIp()) returns null, causing Environment#isMatch(null) in AclAuthorizationHandler#matchPolicyEntries to throw NullPointerException instead of returning false.

This PR adds a null check for environment in Environment#isMatch so it returns false, and adds a unit test in AclAuthorizationHandlerTest.

How Did You Test This Change?

  • Ran mvn test -pl auth -Dtest=AclAuthorizationHandlerTest (Checkstyle: 0 violations, SpotBugs: 0 errors, Tests run: 11, Failures: 0, Errors: 0).

@codecov-commenter

codecov-commenter commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 49.89%. Comparing base (28960fd) to head (befa7ed).

Additional details and impacted files
@@              Coverage Diff              @@
##             develop   #11545      +/-   ##
=============================================
+ Coverage      49.86%   49.89%   +0.02%     
- Complexity     14454    14459       +5     
=============================================
  Files           1391     1391              
  Lines         103432   103432              
  Branches       13550    13550              
=============================================
+ Hits           51573    51604      +31     
+ Misses         45636    45600      -36     
- Partials        6223     6228       +5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@qingli9374 qingli9374 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The integration test covers the user-visible ACL behavior, and the null guard itself is
correct. One follow-up would make the coverage less environment-dependent: add a small model
test in authorization/model/EnvironmentTest that asserts a constrained environment returns
false for a null request environment, while an environment without an IP constraint still
returns true. The current handler test is skipped on macOS through MixAll.isMac(), so the
direct model test also protects the changed branch in local runs that do not exercise the
ACL metadata setup.

@leaveWhite9088

Copy link
Copy Markdown
Contributor Author

Thanks @qingli9374 for the suggestion! I've added \EnvironmentTest\ under \�uth/src/test/java/org/apache/rocketmq/auth/authorization/model/\ covering both constrained and unconstrained \Environment#isMatch\ cases with
ull\ / empty request environments, and verified locally that \EnvironmentTest\ and \AclAuthorizationHandlerTest\ pass with zero checkstyle/SpotBugs issues.

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] Environment#isMatch throws NullPointerException when request sourceIp is null or empty

3 participants