Skip to content

Record the socket peer address in audit events - #600

Open
MichaelLeeHobbs wants to merge 1 commit into
OpenIntegrationEngine:mainfrom
MichaelLeeHobbs:fix/audit-event-source-ip
Open

MichaelLeeHobbs wants to merge 1 commit into
OpenIntegrationEngine:mainfrom
MichaelLeeHobbs:fix/audit-event-source-ip

Conversation

@MichaelLeeHobbs

Copy link
Copy Markdown
Contributor

Fixes #578

MirthServlet.getRequestIpAddress() returned the X-Forwarded-For header verbatim whenever a client sent one, so any client could choose the source IP stored on login, authorization and message-access events. It now returns request.getRemoteAddr(), which was already the fallback. This is the first item of the issue's suggested fix.

It also closes a second problem the issue doesn't mention. EVENT.IP_ADDRESS is VARCHAR(40) and DefaultEventController.insertEvent logs insert failures without rethrowing them. From reading that code, a header longer than 40 characters would fail the insert and lose the event. I did not reproduce this against a database.

Behavior change

Behind a reverse proxy, events now record the proxy's address instead of the client's. Events are unchanged for clients that connect directly without sending the header.

I left out the trusted-proxy setting the issue proposes, so this PR adds no configuration. If reviewers need proxy support before this merges, I can add it here.

How to verify

  • ./gradlew :server:test --tests '*MirthServletTest'. The new test, getRequestIpAddressIgnoresForwardedForHeader, fails without the change and passes with it.
  • Or log in through the API with an X-Forwarded-For: 10.0.0.5 header and check the IP address on the Login event.

I ran the server unit tests on Windows. 876 ran and 11 failed, all in DICOMSerializerTest and NCPDPSerializerTest. The same 11 fail on main at 8e5e63d without this change. I did not run the live login check.

🤖 Generated with Claude Code

Audit events took their source IP from the client-supplied
X-Forwarded-For header, so any client could forge it (fixes OpenIntegrationEngine#578).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Michael Hobbs <michael.lee.hobbs@gmail.com>

@mgaffigan mgaffigan 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.

Given the status quo is the ability to take forwarded for headers, I presume the appropriate fix is a failure to apply trusted networks - not to ignore the header entirely. I rely upon this behavior today in containerized deploys.

I agree it is reasonable to ignore the header by default. A flat enable/disable list (trust 0.0.0.0/0 and ::0/0) is likely sufficient for now, since listen controls can limit bind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants