Skip to content

fix(providers): inject n8n sessions into custom bodies#9527

Open
mldangelo-oai wants to merge 2 commits into
mainfrom
mdangelo/codex/fix-n8n-session-field-custom-body-20260529
Open

fix(providers): inject n8n sessions into custom bodies#9527
mldangelo-oai wants to merge 2 commits into
mainfrom
mdangelo/codex/fix-n8n-session-field-custom-body-20260529

Conversation

@mldangelo-oai
Copy link
Copy Markdown
Contributor

Summary

  • inject a supplied n8n session ID into rendered custom object bodies when the configured session field is absent
  • preserve explicit session-field values already provided by a custom template
  • cover both automatic injection and explicit-value preservation

Root cause

The n8n provider only added sessionField to its default body. Custom object and JSON-object templates silently omitted the supplied session ID unless users manually repeated {{sessionId}} in the template.

Validation

  • npx vitest run test/providers/n8n.test.ts --sequence.shuffle=false
  • npm run f
  • npm run l

Base issue

  • npm run tsc currently fails on unchanged main fixtures under test/providers/anthropic/ and test/providers/claude-agent-sdk.test.ts because output_tokens_details is not present in the installed Usage type. This PR does not touch those files or types.

@mldangelo-oai mldangelo-oai requested a review from zcrab-oai as a code owner May 29, 2026 12:41
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3f76cdf150

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/providers/n8n.ts
}

const sessionField = this.config.sessionField || 'sessionId';
return body[sessionField] === undefined ? { ...body, [sessionField]: sessionId } : body;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve non-object custom bodies

When a string body template renders/parses to a JSON array or other non-object JSON value and vars.sessionId is set, this helper now treats it as an object because only strings are excluded. The spread then converts arrays into objects like {"0": ..., "sessionId": ...}, corrupting payloads that were previously sent as arrays; injection should be limited to plain object bodies.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

@promptfoo-scanner promptfoo-scanner Bot left a comment

Choose a reason for hiding this comment

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

👍 All Clear

I reviewed the n8n provider changes that add a helper to inject a session identifier into request bodies across default and custom body paths. The update centralizes prior logic without expanding capabilities or changing prompt handling semantics. Based on the diff, there are no new LLM security risks such as prompt injection, data exfiltration, secrets-in-prompts, insecure output handling, excessive agency, or jailbreak issues.

Minimum severity threshold: 🟡 Medium | To re-scan after changes, comment @promptfoo-scanner
Learn more


Was this helpful?  👍 Yes  |  👎 No 

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.

1 participant