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

@MichaelLeeHobbs MichaelLeeHobbs commented Nov 25, 2026 •

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.

#620 adds the opt-in trusted-proxy setting. With both merged, a proxied deploy lists its proxy in server.api.trustedproxies and events record the forwarded client address again.

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.

@MichaelLeeHobbs

Copy link
Copy Markdown
Contributor Author

Thanks. #620 adds that: server.api.trustedproxies, blank by default, applies the forwarded headers only when the connection comes from a listed address, CIDR block or range. For those requests Jetty sets getRemoteAddr() from X-Forwarded-For, and with this PR that's the address the audit events record. For your containerized deploys, server.api.trustedproxies = 0.0.0.0/0, ::/0 trusts every peer as you suggested, or you can list only the proxy's network.

The two are meant to land together. Merging #620 first, or both at once, avoids a window where proxied deploys record the proxy's address. Does that cover it, or would you rather have both in one PR?

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.

Forgeable source IP in security audit / PHI-access event records (unvalidated X-Forwarded-For trust)

2 participants