Skip to content

fix bug: handle non-UUID path segment in POST/GET/DELETE /apikeys - #786

Merged
naphelps merged 1 commit into
open-horizon:masterfrom
wenyang-cao:fix_bug/issue1731
Jul 7, 2025
Merged

fix bug: handle non-UUID path segment in POST/GET/DELETE /apikeys#786
naphelps merged 1 commit into
open-horizon:masterfrom
wenyang-cao:fix_bug/issue1731

Conversation

@wenyang-cao

@wenyang-cao wenyang-cao commented Jun 25, 2025

Copy link
Copy Markdown
Contributor

Issue: #785

Expected

  • POST only matches exact /apikeys (pathEnd)
  • GET and DELETE should validate keyid as UUID and return 400 if malformed

@naphelps @kroczi

Please take a look.

Since the change involves wrapping at a higher level, there's a lot of indentation diff — please review with ?w=1: https://github.com/open-horizon/exchange-api/pull/786/files?w=1

Haven't updated changelog since I am not sure what version it would be when it is ready to be merged.

Comment on lines 319 to +321
def routeMethods(resourceIdentity: Option[UUID]): Route = {
post {
exchAuth(TUser(resource, resourceIdentity), Access.WRITE, validIdentity = identity) { _ =>
postUserApiKey(identity, organization, username, resourceIdentity)
pathEnd {
post {

@kroczi kroczi Jun 27, 2025

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.

Wouldn't this pathEnd guard here be enough?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If we only add a pathEnd here, requests like GET /orgs/testorg/users/testuser/apikeys/123 or DELETE /orgs/testorg/users/testuser/apikeys/123 will not mismatch POST and return 405 Method Not Allowed as Krystian reported. Instead, it will return a 404 Unrecognised route. This because the previous implementation, GET and DELETE only accepts UUIDs, so a non-UUID string will not match any route.

In my current commit these requests will return 400 Invalid UUID format for API key ID. I personally feel this is a more appropriate response. Let me know what you think.

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.

Thanks for explanation. I definitely think that 404 Unrecognised route or 405 Method Not Allowed would be out of place. There should be returned either404 Resource Not found or your 400 Bad Request. I think your solution is more user-friendly (in case of a typo).

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

Changes look good.

@kroczi

kroczi commented Jul 7, 2025

Copy link
Copy Markdown
Contributor

@naphelps Please merge.

Signed-off-by: wenyang-cao <wenyang.cao@ibm.com>
@naphelps
naphelps self-requested a review July 7, 2025 16:29

@naphelps naphelps left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@naphelps
naphelps merged commit 25fee68 into open-horizon:master Jul 7, 2025
2 checks passed
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.

3 participants