Skip to content

fix: preserve JSON types when extracting integration variables#3820

Open
Copilot wants to merge 2 commits intodevelopfrom
copilot/fix-integrations-json-forwarding
Open

fix: preserve JSON types when extracting integration variables#3820
Copilot wants to merge 2 commits intodevelopfrom
copilot/fix-integrations-json-forwarding

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 2, 2026

When extracting JSON body values in integrations, all values were converted to strings via fmt.Sprintf("%v", val), causing JSON objects to be passed as Go's internal representation (map[id:2 name:test]) instead of proper JSON structures.

Changes

  • api/integration.go: Changed Extract return type from map[string]string to map[string]any, dropping the fmt.Sprintf("%v", val) coercion so gojsonq values are passed through as native Go types — objects as map[string]interface{}, arrays as []interface{}, numbers as float64, booleans as bool
  • api/integration_test.go: Updated type assertions to match correct native types; added TestExtract_JSONBody_ObjectPreservedAsMap and TestGetTaskDefinition_JSONObjectInEnv covering the reported scenario end-to-end

Before / After

# Payload: {"data":{"id":2,"name":"test"}}

# Before — Ansible sees a string
ok: [localhost] => data: map[id:2 name:test]

# After — Ansible sees a proper dict
ok: [localhost] => data:
    id: 2
    name: test

The Extract function now returns map[string]any instead of map[string]string,
preserving JSON types (objects, arrays, numbers, booleans) instead of
converting them to Go string representations via fmt.Sprintf("%v", val).

Previously, a JSON payload like {"data":{"id":2,"name":"test"}} would produce
the environment variable data="map[id:2 name:test]" (Go's internal format).
Now it is correctly forwarded as a proper JSON dict {"id":2,"name":"test"}.

Also adds TestGetTaskDefinition_JSONObjectInEnv and
TestExtract_JSONBody_ObjectPreservedAsMap to verify the fix.

Agent-Logs-Url: https://github.com/semaphoreui/semaphore/sessions/5bb1f79a-b7b0-4c5a-a224-4fc41c67e920

Co-authored-by: fiftin <914224+fiftin@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix integrations JSON not correctly forwarded to task template fix: preserve JSON types when extracting integration variables May 2, 2026
Copilot AI requested a review from fiftin May 2, 2026 14:01
Copilot finished work on behalf of fiftin May 2, 2026 14:01
@fiftin fiftin marked this pull request as ready for review May 2, 2026 14:02
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Security review (automation)

Scope: api/integration.go change to Extract return type map[string]any and preserve native JSON values from gojsonq instead of fmt.Sprintf("%v", val); related tests.

Prior threads: Cleaned up previous automation review artifacts; re-validated against the current diff.

Findings: None at medium or higher confidence.

Rationale (summary): Webhook payload is still only accepted after the integration’s configured auth (HMAC, token, basic, or none) and optional matchers. The change only alters how parsed JSON is represented when merging into task environment (json.Marshal/Unmarshal) and task params (ExtractParams marshals Params then json.Unmarshal into typed structs). Nested maps/slices are handled by encoding/json as before for env merging; scalars now round-trip as JSON booleans/numbers instead of strings, which avoids json.Unmarshal failures into typed task-param structs rather than introducing a new trust boundary.


Slack summary: PR #3820 security pass — no medium/high/critical issues. Integration webhook extraction now keeps native JSON types for env/task params; auth model unchanged; no new injection or authz bypass identified in the diff.

Open in Web View Automation 

Sent by Cursor Automation: Find vulnerabilities

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.

Problem: Integrations JSON not correctly forwarded to the task template

2 participants