Skip to content

Conversation

@anoadragon453
Copy link
Member

@anoadragon453 anoadragon453 commented Jan 23, 2026

Fixes #19395 by checking for /health exactly (Twisted didn't appear to make it easy to use a regex here - and an exact str check is quicker than a regex match anyhow).

Pull Request Checklist

  • Pull request is based on the develop branch
  • Pull request includes a changelog file. The entry should:
    • Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from EventStore to EventWorkerStore.".
    • Use markdown where necessary, mostly for code blocks.
    • End with either a period (.) or an exclamation mark (!).
    • Start with a capital letter.
    • Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry.
  • Code style is correct (run the linters)

Comment on lines +41 to +46
request.setResponseCode(404)
body = (
'{"errcode":"'
+ Codes.UNRECOGNIZED
+ '","error":"Unrecognized request"}'
)
Copy link
Member Author

Choose a reason for hiding this comment

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

I wasn't able to use a UnrecognizedRequestError here directly as no calling function would catch and convert it. And I didn't want to hardcode M_UNRECOGNIZED in case it ever changed.

I also didn't want to construct an object and then convert that to JSON, as the health endpoint is supposed to be fast.

Copy link
Member

Choose a reason for hiding this comment

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

This seems like a good approach to keep the /health endpoint logic as simple as possible and speedy.

@anoadragon453 anoadragon453 marked this pull request as ready for review January 23, 2026 15:59
@anoadragon453 anoadragon453 requested a review from a team as a code owner January 23, 2026 15:59
Copy link
Member

@devonh devonh left a comment

Choose a reason for hiding this comment

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

Thank you for taking this on so quickly and just getting it out of the way :)

Comment on lines +41 to +46
request.setResponseCode(404)
body = (
'{"errcode":"'
+ Codes.UNRECOGNIZED
+ '","error":"Unrecognized request"}'
)
Copy link
Member

Choose a reason for hiding this comment

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

This seems like a good approach to keep the /health endpoint logic as simple as possible and speedy.

"""
channel = self.make_request("GET", "/health/extra/path", shorthand=False)

self.assertEqual(channel.code, 404)
Copy link
Member

Choose a reason for hiding this comment

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

Should we also test the error body for completeness sake?
Similar to what we do for testing generic server requests

Suggested change
self.assertEqual(channel.code, 404)
self.assertEqual(channel.code, 404)
self.assertEqual(channel.json_body["error"], "Unrecognized request")
self.assertEqual(channel.json_body["errcode"], "M_UNRECOGNIZED")

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.

The /health resource allows for path traversal

3 participants