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.
Example
Let’s say we have a function called hello
and this redirect in the netlify.toml
:
[[redirects]]
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:
https://my-site.netlify.app/somePage/http%3A%2F%2Fexample.com%2F
Function payload
This is what the event
object passed into the function looks like before and after our fix.
Before:
{
path: '/somePage/http://example.com/',
// ...
}
After:
{
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.