Skip to content

fix(governance): validate workflow edge conditions and node references - #32326

Merged
yan-3005 merged 7 commits into
mainfrom
fix/governance-workflow-edge-condition-validation
Sep 2, 2026
Merged

yan-3005 merged 7 commits into
mainfrom
fix/governance-workflow-edge-condition-validation

Conversation

@yan-3005

@yan-3005 yan-3005 commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes

Governance workflow edge condition values and node references are used to build the Flowable sequence-flow expressions that drive conditional transitions (${from_result == 'condition'}). This PR restricts the values that are interpolated into those expressions so only well-formed input is accepted.

  • Add WorkflowExpressionValidator holding the allowed patterns (a condition must be empty — unconditional — or contain at least one alphanumeric plus space . _ -; a conditional edge's source must be an identifier).
  • Validate the condition and the source node of conditional edges at the create/update boundary in WorkflowDefinitionRepository (rejected with a clear 400). Unconditional edges are untouched, so node names keep the broader entityName contract.
  • Guard expression construction in Edge as a defense-in-depth check.
  • In edge.json: add a pattern/maxLength on condition (aligned with the server-side validator) and minLength/maxLength bounds on from/to.

Legitimate values used across all seed workflows (e.g. approve, reject, true, false, ack, assign, resolve) continue to work unchanged.

Type of change

  • Bug fix

Tests

  • Unit: WorkflowExpressionValidatorTest, EdgeTest, and WorkflowDefinitionRepositoryEdgeSafetyTest — 40 tests, all passing.
  • Manual: ran the server against MySQL + Elasticsearch and confirmed a legitimate conditional workflow is accepted (201) while malformed conditions and source references are rejected (400), and an empty (unconditional) condition is accepted.

Checklist

  • I have read the CONTRIBUTING document.
  • My PR includes tests for the changes made.

Governance workflow edge `condition` values and node names are used to
build Flowable sequence-flow expressions. Restrict them to a safe
character set so only well-formed values are accepted.

- Add WorkflowExpressionValidator with the allowed patterns
- Validate edge conditions and node names in WorkflowDefinitionRepository
- Guard expression construction in Edge
- Add a schema pattern on edge from/to/condition

Covered by unit tests for the validator and Edge.
Copilot AI lite review requested due to automatic review settings September 1, 2026 05:17
@yan-3005
yan-3005 requested a review from a team as a code owner September 1, 2026 05:17
@yan-3005 yan-3005 added the To release Will cherry-pick this PR into the release branch label Sep 1, 2026
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels Sep 1, 2026

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 hardens governance workflow definitions by validating edge condition values and node references used to construct Flowable JUEL expressions, reducing the risk of expression injection while keeping existing seed workflow values working.

Changes:

  • Introduces WorkflowExpressionValidator with safe patterns for edge conditions and node references.
  • Enforces condition and node-name validation at the workflow create/update boundary (WorkflowDefinitionRepository) and at expression-construction time (Edge) for defense in depth.
  • Adds JSON Schema pattern constraints for edge from/to/condition and adds focused unit tests for the new validation behavior.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
openmetadata-spec/src/main/resources/json/schema/governance/workflows/elements/edge.json Adds schema-level regex validation for edge endpoints and condition values.
openmetadata-service/src/main/java/org/openmetadata/service/governance/workflows/WorkflowExpressionValidator.java Centralizes allowlisted patterns for JUEL-interpolated fields.
openmetadata-service/src/main/java/org/openmetadata/service/governance/workflows/elements/Edge.java Guards JUEL expression construction against unsafe from/condition values.
openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/WorkflowDefinitionRepository.java Rejects unsafe node IDs and edge conditions at the persistence boundary with 400s.
openmetadata-service/src/test/java/org/openmetadata/service/governance/workflows/WorkflowExpressionValidatorTest.java Adds unit coverage for safe/unsafe condition and node reference patterns.
openmetadata-service/src/test/java/org/openmetadata/service/governance/workflows/elements/EdgeTest.java Verifies expression output and that unsafe inputs fail fast during edge construction.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

// the value is inert data. Allow the punctuation legitimate conditions use (e.g. "Tier.Gold") but
// exclude every character that could terminate the literal or introduce expression syntax
// (' " \ $ { } ( ) = etc.).
private static final Pattern SAFE_EDGE_CONDITION = Pattern.compile("^[A-Za-z0-9 ._-]+$");
Comment on lines +206 to +211
if (condition != null && !WorkflowExpressionValidator.isSafeCondition(condition)) {
throw BadRequestException.of(
String.format(
"Workflow '%s' has an edge with an unsafe condition: '%s'",
workflowName, condition));
}
Comment on lines 19 to 23
"condition": {
"description": "Defines if the edge will follow a path depending on the source node result.",
"type": "string"
"type": "string",
"pattern": "^[A-Za-z0-9 ._-]+$"
}
Comment on lines +466 to +470
// Node names become JUEL variable-name prefixes on conditional edges; reject any that could
// break out of the generated expression (GHSA-cq2r-82mr-xv2h).
if (!WorkflowExpressionValidator.isSafeNodeReference(nodeId)) {
throw BadRequestException.of(
String.format(
@github-actions

github-actions Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

✅ Playwright Results — workflow succeeded

Validated commit 2345d1904b961738ab0843fe1a19d40aac49a8cd in Playwright run 33542141588, attempt 1.

✅ 790 passed · ❌ 0 failed · 🟡 1 flaky · ⏭️ 0 skipped · 🧰 0 lifecycle flaky

Performance

Blocking targets: ✅ met · Optimization targets: 🟡 in progress

Shard-job maxima below are not the full workflow wall time; the linked run includes build, fixture, planning, and reporting.

🕒 Full workflow signal wall (to summary) 49m 40s

⏱️ Max setup 4m 32s · max shard execution 15m 23s · max shard-job elapsed before upload 18m 27s · reporting 7s

🌐 207.00 requests/attempt · 2.50 app boots/UI scenario · 25.46% common-shard skew

Optimization targets still in progress:

  • Common shard skew was 25.46% (convergence target: at most 15%).
  • Browser traffic was 207 requests per attempt (convergence target: fewer than 200).
  • Application boot ratio was 2.5 per UI scenario (2034 boots / 815 scenarios; convergence target: at most 1).
Shard Passed Failed Flaky Skipped Lifecycle failed Lifecycle flaky
✅ Shard chromium-01 127 0 0 0 0 0
✅ Shard chromium-02 121 0 0 0 0 0
🟡 Shard chromium-03 141 0 1 0 0 0
✅ Shard chromium-04 136 0 0 0 0 0
✅ Shard chromium-05 110 0 0 0 0 0
✅ Shard data-asset-rules-01 63 0 0 0 0 0
✅ Shard domain-isolation-01 16 0 0 0 0 0
✅ Shard global-state-01 33 0 0 0 0 0
✅ Shard ingestion-01 1 0 0 0 0 0
✅ Shard reindex-01 2 0 0 0 0 0
✅ Shard search-01 11 0 0 0 0 0
✅ Shard search-rbac-01 29 0 0 0 0 0
🟡 1 flaky test(s) (passed on retry)
  • Pages/CustomProperties.spec.ts › Date Time (shard chromium-03, 1 retry)

📦 Download artifacts

How to debug locally
# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip    # view trace

… edges

Address review feedback:
- Only validate the condition and source node of edges that carry a
  condition; unconditional edges keep the broader entityName contract, so
  existing workflows with descriptive node names are not rejected on update.
- Treat an empty condition the same as null (unconditional) instead of
  rejecting it; allow empty in the edge.json condition pattern and bound its
  length.
- Improve the 400 messages to name the edge and the allowed characters.
- Add repository-level unit tests for edge validation.
Copilot AI review requested due to automatic review settings September 1, 2026 06:19

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

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

Suppressed comments (1)

openmetadata-spec/src/main/resources/json/schema/governance/workflows/elements/edge.json:21

  • The PR description mentions adding a pattern on edge from/to as well, but the schema still leaves those fields as unconstrained string. To keep the schema consistent with the rest of the spec (and with node naming via entityName), consider referencing basic.json#/definitions/entityName for from and to (which also applies maxLength/pattern).
    "condition": {
      "description": "Defines if the edge will follow a path depending on the source node result.",
      "type": "string",
      "maxLength": 256,
      "pattern": "^[A-Za-z0-9 ._-]*$"

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

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — failed_checks (2026-09-01T17:46:59Z)

Blocked the queue: py-tests-status

  • py-tests-postgres — py-tests-status, python / Verify Expected Jobs, python / Integration Tests (shard-3)
  • py-tests — python / Integration Tests (shard-3), python / Unit Tests & Static Checks (3.10)

@gitar-bot

gitar-bot Bot commented Sep 1, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 2 resolved / 2 findings

Adds input validation for governance workflow edge conditions and node references to prevent malformed Flowable expressions. Validation is enforced at the API boundary with clear 400 responses, guarded in expression construction, and defined via JSON schema patterns. All legitimate values across seed workflows continue to work; existing workflows with now-illegal names or conditions will be blocked on update, and empty-string conditions are rejected by the validator rather than treated as unconditional. 29 tests pass with no failures.

✅ 2 resolved
✅ Edge Case: Existing workflows with now-illegal names/conditions blocked on update

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/WorkflowDefinitionRepository.java:466-472 📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/WorkflowDefinitionRepository.java:199-213
The new charset restrictions run through validateWorkflow on every create AND update (via prepare()), and the seed check only confirmed the shipped seed definitions. Any previously-persisted, user-created workflow whose node names contain spaces/hyphens or whose edge conditions contain characters outside ^[A-Za-z0-9 ._-]+$ will now be rejected with a 400 on any subsequent edit, effectively locking those workflows. Consider auditing existing stored definitions (or scoping the reference-charset check to newly added/changed nodes) to avoid breaking legitimate pre-existing workflows.

✅ Quality: Empty-string condition rejected by validator but treated as unconditional

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/WorkflowDefinitionRepository.java:204-212 📄 openmetadata-service/src/main/java/org/openmetadata/service/governance/workflows/elements/Edge.java:19-21
Edge.java treats a null OR empty condition as an unconditional edge (CommonUtil.nullOrEmpty at line 19), but validateEdgeConditions rejects any non-null condition failing isSafeCondition, and the regex requires 1+ chars — so an edge with condition:"" throws a 400 ("unsafe condition: ''") at the repository boundary and is also rejected by the edge.json pattern, even though it is semantically a valid unconditional edge. Align the boundary check with Edge's semantics by treating empty/blank conditions the same as null (skip them) rather than flagging them as unsafe.

Options

Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

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

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

Suppressed comments (3)

openmetadata-service/src/main/java/org/openmetadata/service/governance/workflows/WorkflowExpressionValidator.java:20

  • SAFE_NODE_REFERENCE currently allows node references starting with a digit (e.g. 1node). Those will be interpolated into a JUEL variable position (${from_result ...}) and are likely to produce a syntactically invalid expression at runtime. Tighten the pattern so the first character is a letter or _ (identifier-like).
  // A conditional edge's source ('from') lands in code position as the JUEL variable-name prefix
  // (${from_result == ...}); a valid variable reference is limited to identifier characters.
  private static final Pattern SAFE_NODE_REFERENCE = Pattern.compile("^[A-Za-z0-9_]+$");

openmetadata-service/src/test/java/org/openmetadata/service/governance/workflows/WorkflowExpressionValidatorTest.java:63

  • This test suite doesn’t currently cover the case where a node reference starts with a digit, which the validator should reject to avoid generating invalid JUEL variable references. Add a digit-leading example and rename the test to reflect the broader invalidity (not just disallowed characters).
  @ParameterizedTest
  @ValueSource(strings = {"a' b", "foo.bar", "node-1", "has space", "${x}"})
  void rejectsNodeReferencesWithDisallowedCharacters(String reference) {
    assertFalse(WorkflowExpressionValidator.isSafeNodeReference(reference));

openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/WorkflowDefinitionRepository.java:229

  • The error for an invalid conditional-edge from reference doesn’t include the rejected value, and (after tightening the regex) should also mention the “must start with letter or '_'” constraint to avoid confusion when debugging 400s.
      throw BadRequestException.of(
          String.format(
              "Workflow '%s' conditional edge '%s' -> '%s' has an invalid source node reference; "
                  + "allowed characters: letters, digits, '_'",
              workflowName, edge.getFrom(), edge.getTo()));

@sonarqubecloud

sonarqubecloud Bot commented Sep 1, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Failed to cherry-pick changes to the 1.13 branch.
Please cherry-pick the changes manually.
You can find more details here.

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Failed to cherry-pick changes to the 2.0 branch.
Please cherry-pick the changes manually.
You can find more details here.

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend safe to test Add this label to run secure Github workflows on PRs To release Will cherry-pick this PR into the release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants