Skip to content

fix: exclude initializeState from entity operation dispatch#278

Open
YunchuWang wants to merge 1 commit into
mainfrom
copilot-finds/bug/entity-dispatch-initializestate
Open

fix: exclude initializeState from entity operation dispatch#278
YunchuWang wants to merge 1 commit into
mainfrom
copilot-finds/bug/entity-dispatch-initializestate

Conversation

@YunchuWang

Copy link
Copy Markdown
Member

Summary

Fixes #225

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>
Copilot AI review requested due to automatic review settings June 18, 2026 17:15

Copilot AI 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.

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 initializeState from TaskEntity operation method dispatch (findMethod) so it can’t be invoked via operation name matching.
  • Add Jest coverage to verify initializeState is 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.

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.

[copilot-finds] Bug: TaskEntity.dispatch() exposes initializeState() lifecycle method as an entity operation

3 participants