Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requests with form-data or x-www-form-data-urlencoded returns error #58152

Closed
1 task done
leonidk101 opened this issue Nov 7, 2023 · 6 comments · Fixed by #60526
Closed
1 task done

Requests with form-data or x-www-form-data-urlencoded returns error #58152

leonidk101 opened this issue Nov 7, 2023 · 6 comments · Fixed by #60526
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team. locked Runtime Related to Node.js or Edge Runtime with Next.js.

Comments

@leonidk101
Copy link

leonidk101 commented Nov 7, 2023

Link to the code that reproduces this issue

https://github.com/lkimrxnt/next-formData-issue

To Reproduce

form-data

  1. Start application in development (port 3000)
  2. Send POST request to the application with any form data:
curl --location 'http://localhost:3000/' \
--form 'username="testUserName"' \
--form 'password="testPassword"'

x-www-form-data-urlencoded

  1. Start application in development (port 3000)
  2. Send POST request to the application with any form data:
curl --location 'http://localhost:3000/' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'username=testUserName' \
--data-urlencode 'password=testPassword'

Current vs. Expected behavior

Current

If form-data or x-www-form-data-urlencoded has been sent the application returns the error below:

Missing `origin` header from a forwarded Server Actions request.
 ⨯ TypeError: s is not a function
    at C:\dev\test-next-app\my-app\node_modules\next\dist\compiled\next-server\app-page.runtime.dev.js:13:5619
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async tE (C:\dev\test-next-app\my-app\node_modules\next\dist\compiled\next-server\app-page.runtime.dev.js:13:4860)
    at async tV (C:\dev\test-next-app\my-app\node_modules\next\dist\compiled\next-server\app-page.runtime.dev.js:13:32468)
    at async doRender (C:\dev\test-next-app\my-app\node_modules\next\dist\server\base-server.js:1294:26)
    at async cacheEntry.responseCache.get.incrementalCache.incrementalCache (C:\dev\test-next-app\my-app\node_modules\next\dist\server\base-server.js:1446:28)
    at async DevServer.renderToResponseWithComponentsImpl (C:\dev\test-next-app\my-app\node_modules\next\dist\server\base-server.js:1361:28)
    at async DevServer.renderPageComponent (C:\dev\test-next-app\my-app\node_modules\next\dist\server\base-server.js:1600:24)
    at async DevServer.renderToResponseImpl (C:\dev\test-next-app\my-app\node_modules\next\dist\server\base-server.js:1638:32)
    at async DevServer.pipeImpl (C:\dev\test-next-app\my-app\node_modules\next\dist\server\base-server.js:826:25)
    at async DevServer.handleCatchallRenderRequest (C:\dev\test-next-app\my-app\node_modules\next\dist\server\next-server.js:623:13)
    at async DevServer.handleRequestImpl (C:\dev\test-next-app\my-app\node_modules\next\dist\server\base-server.js:728:17) {
  page: '/'
}

If x-www-form-data-urlencoded has been sent the equest stuck and never completes

Expected

The application executes logic in the middleware, parses formData and renders root page /

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Pro
Binaries:
  Node: 16.20.0
  npm: N/A
  Yarn: N/A
  pnpm: 8.6.12
Relevant Packages:
  next: 13.5.6
  eslint-config-next: 13.5.6
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.2.2
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

App Router, Middleware / Edge (API routes, runtime)

Additional context

I've tested the same behavior using the latest version of next (14).

Important note

If I send the requests below to a page in Pages routing /pages/testPage, everything works as expected.

curl --location 'http://localhost:3000/testPage' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'username=testUserName' \
--data-urlencode 'password=testPassword'
curl --location 'http://localhost:3000/testPage' \
--form 'username="testPassword"' \
--form 'password="testPassword"'

NEXT-1761

@leonidk101 leonidk101 added the bug Issue was opened via the bug report template. label Nov 7, 2023
@github-actions github-actions bot added the Runtime Related to Node.js or Edge Runtime with Next.js. label Nov 7, 2023
@atomicleopard
Copy link

This is impacting my application which is using inbound webhooks from Slack. I'm trying to receive the call using a Route Handler registered for POST

My application logs Missing origin header from a forwarded Server Actions request. and the handler is never called.

@balazsorban44 balazsorban44 added the linear: next Confirmed issue that is tracked by the Next.js team. label Nov 30, 2023
@feedthejim
Copy link
Contributor

what's the usecase?

@laurens-mesure
Copy link

what's the usecase?

The usecase is using data from x-www-form-data-urlencoded in route handlers?

@rpavlovs
Copy link

Same issue.

I have a POST endpoint that is supposed receive files as form data. It works if do just that, but as soon as I import and try to use logic to process those files I get this error. I'm not sure what exactly is causing this.

Importing Prisma is fine. Do these app router endpoints have anything special about how they are compiled? My runtime is explicitly set to 'nodejs'

@rpavlovs
Copy link

I was able to trace it to this package: https://github.com/AIDungeon/GPT-3-Encoder

Removing import & usage fixed the issue 🤔

huozhi added a commit that referenced this issue Jan 11, 2024
When sending post requests but it's not server action, skip logging
warning or calling non-existed server action. Instead we only log the
warning like missnig headers for server actions when it's a server
action and call the action handler when it's decoded as a function

Fixes #58152 
Closes NEXT-1761
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team. locked Runtime Related to Node.js or Edge Runtime with Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants