Bug fix: URL encoding preserved in Function event

We are about to roll out a bugfix to our Functions engine. I expect this change to be rolling out on the 9th of December.

The Bug

Previously we did decode request URLs when a request for a function came in. In the future we will keep the encoding in place. This means your function code needs to handle url decoding itself. See the following example for the specifics and why it is useful.


Let’s say we have a function called hello and this redirect in the netlify.toml:

from = "/somePage/:someVar"
to = "/.netlify/functions/hello"
status = 200
force = true

(This means all request to /somePage/ with any single-element suffix will be routed to the function.)

Now consider this Request:

Function payload

This is what the event object passed into the function looks like before and after our fix.


  path: '/somePage/http://example.com/',
  // ...


  path: '/somePage/http%3A%2F%2Fexample.com%2F',
  // ...

Why do we need to keep the url encoded?

This is crucial for any code that wants to extract so-called “path parameters” from the URL path. If the parameter itself contains an urlencoded slash and we decode it early on, the function code cannot properly determine where the part of the path ends that we want to extract.

This was first reported in our NextJS compatibility layer - see this issue for a more complete reproduction of the bug: getServerSideProps fails for certain values, probably related to URL encoding or slashes · Issue #98 · netlify/next-on-netlify · GitHub

Could this break existing functions?

Yes it could. If your code relies on the previous behaviour of Netlify decoding the url then you might want to check if you need to adjust your function code. You can use decodeURI to decode URL paths.

We have done some inspection of our incoming traffic and think that very few functions use this pattern. Less than .01% of our accounts have any traffic matching this pattern, in the past 24 hours.

Please let us know if you have any questions around this change and what it would mean for your existing functions or code you write in the future.


This is rolling out right now…

Hi Markus,

TL; DR NextJS projects on Netlify might be broken right now regarding getServerSideProps

In details: getServerSideProps fails for certain values, probably related to URL encoding or slashes · Issue #98 · netlify/next-on-netlify · GitHub

Thanks, Philippe, our team is rolling back the change and will investigate this.


Thank you Chris. I confirm the rollback is effective.

1 Like

appreciate that heads up! We’ll talk internally about next steps and follow up here as things develop.

1 Like

Hi Chris, will there be a postmortem included in the follow up? Thanks

Likely not a deep RCA, no. We rolled this out per this announcement, and the affected people were largely those who use cloudflare in certain ways very much against our advice:

… and in an unsupported configuration:

…were the ones impacted.

If you don’t proxy to us from cloudflare, we’d love to hear about the use case for your site that was impacted so we can make sure to avoid future breakage!

If you don’t proxy to us from cloudflare, we’d love to hear about the use case for your site that was impacted so we can make sure to avoid future breakage!

I can confirm we do not have a proxy in front of Netlify. We have a Next.js site deployed via next-on-netlify as per Philippe’s report above.

All of our Functions were affected.

We definitely introduced an unexpected regression here and I can make sure to write a small RCA for this.

1 Like

Hi @fool,

I don’t understand exactly how the SSL certificate issue connected with this URL encoding changes.

We have different DNS setup:

  • netlify handles the domain (at a registrator we only configured the netlify DNS records): app.brightmeup.ai
  • external registrator handles the DNS, we configured a CNAME record pointing to the netlify domain (app-hirspektrum-hu.netlify.app): app.hirspektrum.hu

We do not use any special proxy setup.

We had serious problems on Dec 9, 2020.
All of our lambda functions on all of our sites responded 404 http error for hours.

I don’t think we should be affected because this URL encoding changes.

We only use English letters, numbers and hyphen in the path part of the urls.
We use the gin (go lang) third party library and it handles the URL encoding with the query string part.
If it’s helping I can share an example public project on github about how we write/use lambda functions.

I’m curious what is count as an incident on your status page, because this incident still isn’t mentioned on it.
If/when we notice a problem, usually one of our first steps to check your status page and your status twitter account…

Best Regards,
Zoltan Imre

Hi @negentropics, I think @fool’s previous statement around SSL and Cloudflare was incorrect. The issue with 404 function responses was caused by an unexpected regression, but @marcus mentioned a small RCA will be forthcoming.

Just a heads up: a change has been rolled out to production today - we should again be preserving url encoding in the functions request paths.

Hi @emily,
What is the status of this bug? Working today, I noticed for our functions, the URL encoding is not preserved in the function event when deployed:

However, the encoding is preserved when developing locally with netlify dev. Is there a reason the behaviours differ between local development and deployed environment?

This bug was resolved awhile back ago. Can your site name/ID?

The details are:
name: cobresun-movie-club
site id: 1d88681f-226e-4972-a2bb-1360f2610294

hi @cole-adams

Can you please provide a way to replicate this behaviour? What path should we hit to see the encoding not being preserved?


Hi @gualter

I have setup a test endpoint:
https://delete-category-bug--cobresun-movie-club.netlify.app/api/test/< encoded string >

That just responds with event.path and and event.rawUrl. After doing this, I’ve discovered that from what I can see, only spaces (%20) are not preserved and only when the only encoded character is a space.

So GET https://delete-category-bug--cobresun-movie-club.netlify.app/api/test/something%20encoded returns

    "path": "/api/test/something encoded",
    "rawUrl": "https://delete-category-bug--cobresun-movie-club.netlify.app/api/test/something%20encoded"

However, GET https://delete-category-bug--cobresun-movie-club.netlify.app/api/test/something%2Fencoded%20here

    "path": "/api/test/something%2Fencoded%20here",
    "rawUrl": "https://delete-category-bug--cobresun-movie-club.netlify.app/api/test/something%2Fencoded%20here"

The event and context are also logged to console in this function.

Very odd. Thank you for your help. Let me know if you need any more information!

wow, great find and thank you!

I’ve gotten a bug written up for our team.

We’ll feed back here if we fix it, but based on the specificity of the situation you described, it sounds like it would impact very few folks and be easy enough for you to work around, so we may not fix it very soon, if it is complicated to do so, just to set expectations.