Skip to content

Use the federated user id as the session audit log initiator when log masking is enabled - #8373

Open
RushanNanayakkara wants to merge 1 commit into
wso2:masterfrom
RushanNanayakkara:fix-28491-audit-initiator-master
Open

RushanNanayakkara wants to merge 1 commit into
wso2:masterfrom
RushanNanayakkara:fix-28491-audit-initiator-master

Conversation

@RushanNanayakkara

Copy link
Copy Markdown
Contributor

Purpose

Related issue: wso2/product-is#28491

With [masking_logs] enabled = true, the session audit log lines (StoreSession, UpdateSession) give a local user an unmasked user ID in Initiator, so the line can be attributed to a user. Federated users get the masked subject in both Initiator and AuthenticatedUser, so the line cannot be attributed to anyone. Organization SSO users (sub-organization users logging in to a root organization application with enhanced organization login disabled) take the same path, because the framework marks them as federated.

What this changes

DefaultAuthenticationRequestHandler.addAuditLogs: for a federated user, when log masking is enabled, Initiator is set to the user ID already set on the AuthenticatedUser. If no user ID is set, the masked subject is used, as before.

The username lookup is still skipped for federated users, so the subject from the external IdP is never logged unmasked. The user ID used instead does not expose it:

User User ID set on the AuthenticatedUser
Federated user The federated user ID from IDN_AUTH_USER, set by DefaultStepHandler after the federated step
Organization SSO user The user's ID in the resident organization

No user ID is looked up or stored by this change; it only reads the field when isUserIdExists() is true. AuthenticatedUser stays masked. Behaviour with log masking disabled is unchanged.

The Login audit line is written by identity-data-publisher-authentication and is not changed here.

Testing

Measured on the IS 7.4.0 nightly wso2is-7.4.0-20261020.072933-234 (framework 7.11.236, H2, JDK 25) by driving logins end to end and reading audit.log. DefaultAuthenticationRequestHandler is the same in v7.11.236 and on master. The unmodified class compiles to the same bytecode, line and local variable tables as the shipped one, so the stock and patched runs differ only by this change.

Case (masking on unless stated) Stock Initiator Patched Initiator
Local user user ID user ID (unchanged)
Federated user (OIDC IdP) masked subject federated user ID (the sub the application receives)
Organization SSO user, enhanced organization login disabled, root organization line masked subject user ID in the sub-organization
Masking off, all three user types baseline identical to baseline

AuthenticatedUser is masked in every masked run. With enhanced organization login enabled, the user logs in directly in the sub-organization and no federated session line is written, so that flow is not affected.

The fallback (federated user with no user ID set, masked subject kept) was exercised on IS 7.1.0 with the same code, by clearing the user ID in a debugger.

Framework module unit tests could not be run meaningfully on the test machine: it has JDK 25 only, and Mockito inline mocks fail there. With net.bytebuddy.experimental=true, base and this change give the same result (961 run, the same 28 failures), but DefaultAuthenticationRequestHandlerTest is skipped in both because its setUp fails in Mockito. The CI run on this pull request is the unit test result for this change.

… masking is enabled

For federated users, including organization SSO users, the session audit
log initiator fell back to the masked subject, so the line could not be
attributed to a user. Use the user id already set on the authenticated
user instead. It is an internal identifier and does not expose the
subject. The masked subject is still used when no user id is set.
@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: wso2/carbon-identity-framework/.coderabbit.yml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 939cf35f-2792-4ce7-9329-00a8217389c7
📥 Commits

Reviewing files that changed from the base of the PR and between 00259fc and 5846892.

📒 Files selected for processing: 1
  • components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/handler/request/impl/DefaultAuthenticationRequestHandler.java

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

📝 Walkthrough

Federated audit entries now use the authenticated user’s internal ID when available. If the ID is unavailable or its lookup fails, the handler uses the masked username.

Changes: Federated audit initiator

Layer / File(s) Summary
Resolve federated audit initiator
components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/handler/request/impl/DefaultAuthenticationRequestHandler.java
Federated audit entries use the user ID when available. If the ID is missing or lookup fails, the handler logs the failure when applicable and uses the masked username.

Suggested reviewers: yasasr1

Priority: ⬇️ Low

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 58468

The audit initiator behavior is consistent with the stated change, with no actionable merge-blocking risk identified.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Description check Warning The description clearly explains the purpose, implementation, affected flows, fallback behavior, issue reference, and testing results. However, it omits most template sections, including Goals, User s… Add the missing template sections. Mark non-applicable sections as N/A with a brief explanation, and provide the required security checks, automation test details, release note, documentation impact, test environment, and related PR informa…
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly describes the main change: using the federated user ID as the session audit log initiator when log masking is enabled.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description clearly explains the purpose, implementation, affected flows, fallback behavior, issue reference, and testing results. However, it omits most template sections, including Goals, User stories, Release note, Documentation, Training, Certification, Marketing, Automation tests, Security checks, Samples, Related PRs, Migrations, and Learning.

Resolution

Add the missing template sections. Mark non-applicable sections as N/A with a brief explanation, and provide the required security checks, automation test details, release note, documentation impact, test environment, and related PR information.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@coderabbitai
coderabbitai Bot requested a review from Yasasr1 October 21, 2026 10:49
@sonarqubecloud

Copy link
Copy Markdown

@jenkins-is-staging

Copy link
Copy Markdown

PR builder started
Link: https://github.com/wso2/product-is/actions/runs/39588134633

@jenkins-is-staging

Copy link
Copy Markdown

PR builder completed
Link: https://github.com/wso2/product-is/actions/runs/39588134633
Status: success

@jenkins-is-staging jenkins-is-staging 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.

Approving the pull request based on the successful pr build https://github.com/wso2/product-is/actions/runs/39588134633

@codecov

codecov Bot commented Oct 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 54.91%. Comparing base (5b2e01a) to head (5846892).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
...uest/impl/DefaultAuthenticationRequestHandler.java 0.00% 6 Missing ⚠️

❌ Your patch check has failed because the patch coverage (0.00%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #8373   +/-   ##
=========================================
  Coverage     54.90%   54.91%           
  Complexity    22746    22746           
=========================================
  Files          2277     2277           
  Lines        133919   133925    +6     
  Branches      22204    22206    +2     
=========================================
+ Hits          73534    73542    +8     
+ Misses        51562    51560    -2     
  Partials       8823     8823           
Flag Coverage Δ
unit 40.43% <0.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

2 participants