fix: exclude initializeState from entity operation dispatch#278
Open
YunchuWang wants to merge 1 commit into
Open
fix: exclude initializeState from entity operation dispatch#278YunchuWang wants to merge 1 commit into
YunchuWang wants to merge 1 commit into
Conversation
TaskEntity.findMethod() walks the prototype chain to find methods matching an entity operation name. It excludes 'constructor' and 'run', but not 'initializeState'. When users override initializeState() in their entity subclass (which is the common pattern), it becomes discoverable and can be invoked as a regular entity operation by external callers. This allows any client to send an 'initializeState' operation, silently resetting the entity's state to its initial value — a security and correctness issue. Add 'initializeState' to the exclusion list in findMethod() and add tests verifying lifecycle methods are not dispatchable. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes an entity-operation dispatch bug in the Durable Task JS SDK by preventing TaskEntity.initializeState() (a lifecycle hook commonly overridden by users) from being callable as an external entity operation, aligning behavior with the expected entity contract and closing issue #225.
Changes:
- Exclude
initializeStatefromTaskEntityoperation method dispatch (findMethod) so it can’t be invoked via operation name matching. - Add Jest coverage to verify
initializeStateis rejected as an operation (including case-insensitive matching) while still being invoked internally for state initialization.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/durabletask-js/src/entities/task-entity.ts | Updates method-discovery dispatch to exclude initializeState from callable operations. |
| packages/durabletask-js/test/task-entity.spec.ts | Adds tests ensuring initializeState/run are not dispatchable operations and that internal state initialization still works. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #225