Skip to content

Conversation

@soartec-lab
Copy link
Member

fix #2599

Copilot AI review requested due to automatic review settings December 1, 2025 09:36
Copy link
Contributor

Copilot AI left a comment

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 adds support for variable expansion (template literals) in override.requestOptions.headers for the fetch client. Previously, header values were stringified directly, but now they are rendered as template literals to allow dynamic values like environment variables.

Key Changes:

  • Modified header generation to use template literal syntax instead of direct stringification
  • Added test configuration demonstrating the new capability with environment variable interpolation

Reviewed changes

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

File Description
packages/fetch/src/index.ts Changed header generation logic to use template literals for variable expansion support
tests/configs/fetch.config.ts Added test configuration demonstrating environment variable usage in headers

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +237 to +240
const overrideHeaders =
isObject(override.requestOptions) && override.requestOptions.headers
? Object.entries(override.requestOptions.headers).map(
([key, value]) => `'${key}': \`${value}\``,
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

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

Header keys and values are not sanitized before being inserted into template literals. If user-provided values contain backticks or other special characters, this could result in code injection. Consider escaping special characters in both key and value, particularly backticks, backslashes, and ${ sequences.

Suggested change
const overrideHeaders =
isObject(override.requestOptions) && override.requestOptions.headers
? Object.entries(override.requestOptions.headers).map(
([key, value]) => `'${key}': \`${value}\``,
// Helper functions to escape header keys and values for safe code generation
function escapeHeaderKey(key: string): string {
// Escape single quotes and backslashes
return key.replace(/\\/g, '\\\\').replace(/'/g, "\\'");
}
function escapeHeaderValue(value: string): string {
// Escape backticks, backslashes, and `${`
return value
.replace(/\\/g, '\\\\')
.replace(/`/g, '\\`')
.replace(/\$\{/g, '\\${');
}
const overrideHeaders =
isObject(override.requestOptions) && override.requestOptions.headers
? Object.entries(override.requestOptions.headers).map(
([key, value]) => `'${escapeHeaderKey(key)}': \`${escapeHeaderValue(String(value))}\``,

Copilot uses AI. Check for mistakes.
@melloware melloware merged commit 8a1c129 into orval-labs:master Dec 1, 2025
2 checks passed
@soartec-lab soartec-lab added enhancement New feature or request fetch Fetch client related issue labels Dec 3, 2025
@soartec-lab soartec-lab added this to the 7.17.0 milestone Dec 3, 2025
@soartec-lab soartec-lab self-assigned this Dec 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request fetch Fetch client related issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

support variable expansion in override.requestOptions.headers of fetch client

2 participants