Mitigation Strategy: Principle of Least Privilege for State (Workflow-Kotlin Focused)
-
Description:
- Minimize
State
Scope: Create separatedata class
es for theState
of eachWorkflow
and sub-Workflow
. Avoid a single, large state object. EachState
class should only contain data absolutely necessary for that specific workflow. - Visibility Modifiers within
Workflow
: Use Kotlin's visibility modifiers (private
,internal
,protected
) within yourWorkflow
andState
classes. Restrict access to state properties. Only expose what is absolutely necessary. Avoidpublic
for state properties unless strictly required for rendering (and even then, prefer a separateRenderingT
). - Careful
RenderingT
Design: Review allRenderingT
types. If aRenderingT
directly includes sensitive state, create a separate DTO (Data Transfer Object). This DTO should contain only the data needed for display, transforming the internalState
into a safe-to-expose representation. - Controlled Event Propagation: Define custom, strongly-typed event classes (e.g.,
data class UserLoggedIn(val userId: String)
). Avoid generic event types. In theWorkflow
'sonAction
, only emit events that are necessary. Be explicit about which workflows subscribe to which events using theWorkflow
APIs.
- Minimize
-
Threats Mitigated:
- Unintentional State Exposure / Leaks (Severity: High): Reduces exposure through renderings, events, or direct access to the
Workflow
's state. - Workflow Composition Vulnerabilities (Severity: Medium): Limits state accessible to child
Workflow
s, reducing unintended interactions.
- Unintentional State Exposure / Leaks (Severity: High): Reduces exposure through renderings, events, or direct access to the
-
Impact:
- Unintentional State Exposure / Leaks: Significant reduction.
- Workflow Composition Vulnerabilities: Moderate reduction.
-
Currently Implemented:
- Visibility modifiers used in
WorkflowA
andWorkflowB
state. - Separate DTOs for rendering in
WorkflowC
. - Strongly-typed events for user authentication.
- Visibility modifiers used in
-
Missing Implementation:
WorkflowD
uses a large state object. Needs refactoring.WorkflowE
exposes sensitive state inRenderingT
. Needs a DTO.- Generic events used between
WorkflowF
andWorkflowG
.
Mitigation Strategy: Isolate Side Effects with Worker
s
-
Description:
- Identify Side Effects: List all external interactions (databases, APIs, etc.).
- Create
Worker
s: For each distinct side effect, create a separateWorker
implementation. TheWorker
should encapsulate only that specific side effect. Worker
Input Validation: Treat the input to theWorker
as untrusted. Implement rigorous input validation within theWorker
'srun
method to ensure the input conforms to expected types, ranges, and formats. Use Kotlin's type system.- Rate Limiting/Circuit Breakers (Using Workers): While the implementation of rate limiting and circuit breakers might be external, the decision to apply them and the integration point is within the
Workflow
that uses theWorker
. You would use theWorker
API to handle the results of these patterns (e.g., checking for aWorker
result indicating a rate limit was hit).
-
Threats Mitigated:
- Side Effect Mismanagement / Injection (Severity: High): Isolates side effects, making them easier to audit and control.
- Denial of Service (DoS) via Workflow Overload (Severity: Medium): Rate limiting and circuit breakers, integrated through the
Worker
API, help.
-
Impact:
- Side Effect Mismanagement / Injection: Significant reduction.
- Denial of Service (DoS): Moderate reduction.
-
Currently Implemented:
- Database interactions in
DatabaseWorker
. - API calls to ServiceX in
ServiceXWorker
. - Input validation in
ServiceXWorker
.
- Database interactions in
-
Missing Implementation:
FileAccessWorker
lacks input validation.- Rate limiting/circuit breakers not integrated for
ServiceXWorker
orServiceYWorker
.
Mitigation Strategy: Well-Defined Workflow Contracts (Using Workflow
APIs)
-
Description:
- Define Inputs/Outputs/Events: For each
Workflow
, especially child workflows, clearly define:- Inputs: Strongly-typed
data class
es for data received from the parent. - Outputs: Strongly-typed
data class
es for data returned to the parent. - Events: Strongly-typed event classes the child
Workflow
might emit.
- Inputs: Strongly-typed
- Limit Parent Access: Avoid giving child
Workflow
s direct access to the parentWorkflow
's state. Pass data explicitly through inputs and outputs. - Review
compose
Method: In the parentWorkflow
'scompose
method, carefully review:- How child
Workflow
s are instantiated and configured. - How inputs are passed to child
Workflow
s. - How outputs from child
Workflow
s are handled. - How events from child
Workflow
s are handled. Use theWorkflow
's event handling mechanisms to manage subscriptions.
- How child
- Define Inputs/Outputs/Events: For each
-
Threats Mitigated:
- Workflow Composition Vulnerabilities (Severity: Medium): Reduces unintended interactions between parent and child
Workflow
s. - Unintentional State Exposure / Leaks (Severity: Medium): Limits access to parent's state.
- Workflow Composition Vulnerabilities (Severity: Medium): Reduces unintended interactions between parent and child
-
Impact:
- Workflow Composition Vulnerabilities: Moderate reduction.
- Unintentional State Exposure / Leaks: Moderate reduction.
-
Currently Implemented:
WorkflowH
andWorkflowI
have defined input/output classes.
-
Missing Implementation:
WorkflowK
lacks definitions, interacts with parent's state. Needs refactoring.WorkflowL
'scompose
method needs review.
Mitigation Strategy: Workflow Timeouts (Using withTimeout
in Workflow
)
-
Description:
- Identify Long-Running Workflows: Analyze workflows for potential long-running operations.
- Implement Timeouts: Use Kotlin coroutines'
withTimeout
orwithTimeoutOrNull
functions within theWorkflow
'scompose
oronAction
methods, especially when launching child workflows orWorker
s. This ensures that the timeout is managed within theworkflow-kotlin
context.
-
Threats Mitigated:
- Denial of Service (DoS) via Workflow Overload (Severity: Medium): Prevents workflows from running indefinitely.
-
Impact:
- Denial of Service (DoS): Significant reduction.
-
Currently Implemented:
- Timeouts for long-running workflows using
withTimeout
.
- Timeouts for long-running workflows using
-
Missing Implementation:
- Needs more comprehensive application across all potentially long-running workflows and workers.
Mitigation Strategy: Idempotency within Workflows
-
Description:
- Analyze Workflow Actions: Examine each
Workflow
'sonAction
method and anyWorker
interactions. Identify operations that modify external state (databases, APIs, etc.). - Design for Idempotency:
- Conditional Updates: Before performing an update, check if the update has already been applied. For example, if inserting a record into a database, check if a record with the same unique identifier already exists.
- Unique Request IDs: If interacting with external APIs, include a unique request ID in each request. The API can then use this ID to detect and prevent duplicate processing.
- Use
Worker
Results: Leverage theWorker
API to check for successful completion of previous operations before retrying.
- Test for Idempotency: Write specific tests that repeatedly execute the same
Workflow
actions with the same inputs to verify that the outcome is consistent.
- Analyze Workflow Actions: Examine each
-
Threats Mitigated:
- Replay Attacks / State Corruption (Severity: Medium): Reduces the impact of replaying a workflow or restoring a previous state.
-
Impact:
- Replay Attacks / State Corruption: Moderately reduces the risk and impact.
-
Currently Implemented:
- Partial idempotency implemented in
WorkflowM
for database updates.
- Partial idempotency implemented in
-
Missing Implementation:
- Needs a comprehensive review and implementation across all workflows that modify external state, particularly
WorkflowN
and interactions withServiceZWorker
.
- Needs a comprehensive review and implementation across all workflows that modify external state, particularly