Skip to content

Node 22.3.0 regression: undici sends invalid origin header in some cases #3334

Closed
@mickdermack

Description

Bug Description

Since v6.16.1, undici sends the origin header as origin: https://origin.example.com, undefined in some cases.

This reproducibly happens when sending a POST request, with the origin header explicitly specified in headers and redirect: "error".

Reproducible By

import { fetch } from 'undici';

async function repro() {
  let api_url = "http://localhost:8080";
  let response = await fetch(api_url, {
    "headers": {        
      "origin": "https://origin.example.com"            
    },
    "body": "",    
    "method": "POST",
    "redirect": "error"
  });
}

await repro();

Expected Behavior

I expected the origin header to be sent as origin: https://origin.example.com.

Logs & Screenshots

complete request sent with undici v6.16.1 and above:

POST / HTTP/1.1
host: localhost:8080
connection: keep-alive
origin: https://origin.example.com, undefined
content-type: text/plain;charset=UTF-8
accept: */*
accept-language: *
sec-fetch-mode: cors
user-agent: undici
accept-encoding: gzip, deflate
content-length: 0

complete request sent with undici v6.16.0:

POST / HTTP/1.1
host: localhost:8080
connection: keep-alive
origin: https://origin.example.com
content-type: text/plain;charset=UTF-8
accept: */*
accept-language: *
sec-fetch-mode: cors
user-agent: undici
accept-encoding: gzip, deflate
content-length: 0

Environment

Arch Linux, Node.js v22.3.0

Additional context

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions