Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Actor ID validation #539

Merged
merged 7 commits into from
Nov 28, 2023
Merged

Conversation

heunghingwan
Copy link
Contributor

Description

Throw when actor id contain '/'

Issue reference

issue this PR will close: #537

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation

Signed-off-by: heunghingwan <[email protected]>
@heunghingwan heunghingwan requested review from a team as code owners October 18, 2023 19:48
@heunghingwan
Copy link
Contributor Author

Add empty checking after some reading in dapr/dapr#6461

Take for example the route v1.0/state/{storeName}/{key}. Before, passing an empty {storeName}, such as v1.0/state//somekey would have still invoked the handler, which would have received an empty "storeName" (and likely returned 400 - bad request). Because the router now normalizes paths and removes double slashes (see dapr/dapr#6324), the path is converted to v1.0/state/somekey, so it now returns a 404 because it can't match any route.

Copy link
Contributor

@XavierGeerinck XavierGeerinck 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 adding a test!!! Almost there, just a small change :)

src/actors/ActorId.ts Outdated Show resolved Hide resolved
@XavierGeerinck
Copy link
Contributor

Can we still change if (id === "") throw new Error("ActorId cannot be empty"); ?

Signed-off-by: heunghingwan <[email protected]>
@heunghingwan
Copy link
Contributor Author

Can we still change if (id === "") throw new Error("ActorId cannot be empty"); ?

Yes, it will be more versatile when importing in a javascript-only application

@XavierGeerinck
Copy link
Contributor

Can we still change if (id === "") throw new Error("ActorId cannot be empty"); ?

Yes, it will be more versatile when importing in a javascript-only application

Perfect! But please use the multi line if instead of single one

if (!id) {
...
}

Signed-off-by: heunghingwan <[email protected]>
@shubham1172
Copy link
Member

@heunghingwan were you able to test your scenario from the issue with this PR?

const result = await this.client.execute(`/actors/${actorType}/${actorId.getId()}/state/${key}`);

Since we are decoding back in getId, it should still not work since the ID will contain special characters again.

@heunghingwan
Copy link
Contributor Author

@heunghingwan were you able to test your scenario from the issue with this PR?

const result = await this.client.execute(`/actors/${actorType}/${actorId.getId()}/state/${key}`);

Since we are decoding back in getId, it should still not work since the ID will contain special characters again.

You are right, maybe add a getURISafeId function, or encoded in ActorClientHTTP.ts, to provide unencoded id for grpc use?

@codecov
Copy link

codecov bot commented Oct 27, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (b063e10) 100.00% compared to head (59379c8) 100.00%.
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #539   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines            6         6           
  Branches         1         1           
=========================================
  Hits             6         6           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@shubham1172
Copy link
Member

@XavierGeerinck one issue I see with this change is, we are introducing a parity between HTTP and gRPC actor clients. HTTP will use a sanitized actor ID, and gRPC won't. This means there will be interop issues b/w the two protocols.

I would propose to modify gRPC's behavior too and keep it consistent. Thoughts?

@heunghingwan
Copy link
Contributor Author

@XavierGeerinck one issue I see with this change is, we are introducing a parity between HTTP and gRPC actor clients. HTTP will use a sanitized actor ID, and gRPC won't. This means there will be interop issues b/w the two protocols.

I would propose to modify gRPC's behavior too and keep it consistent. Thoughts?

It should not behave differently, actor ID in gRPC is transmitted as-is, actor ID in HTTP should be decoded in core

@shubham1172
Copy link
Member

@heunghingwan I see, it should be fine in that case, thanks for your contribution!

@shubham1172 shubham1172 added this pull request to the merge queue Nov 28, 2023
Merged via the queue into dapr:main with commit 46c83d9 Nov 28, 2023
7 of 8 checks passed
@heunghingwan heunghingwan deleted the validate-actor-id branch November 30, 2023 09:11
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.

ActorId accepts invalid IDs, causing issues when making Actor HTTP calls
3 participants