menu

ZEIT

Our mission is to make cloud computing as easy and accessible as mobile computing. You can find our Next.js community here.

Channels
Team

Double URL-encoding

October 21, 2019 at 9:39pm
The ZEIT community has a new home. This thread is preserved for historical purposes. The content of this conversation may be innaccurrate or out of date. Go to new community home →

Double URL-encoding

October 21, 2019 at 9:39pm
Hi! I am having a zeit now lambda on PY. When i send a URL which has a space character encoded ONCE, i get an error that the application can't interpret the URL with a space character.
Meaning the application has somewhere decoded my initial URL and passed it to the app. Is that a known issue?

October 21, 2019 at 10:06pm
And here the error:
URL can't contain control characters. '/a/b?origin_city=Moscow&destination_city=Saint Petersburg&currency=usd&destination_country=Russia&origin_country=Russia' (found at least ' '): InvalidURL
Traceback (most recent call last):
File "/var/task/now__handler__python.py", line 57, in now_handler
conn.request(method, path, headers=headers, body=request_body)
File "/var/lang/lib/python3.6/http/client.py", line 1254, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/var/lang/lib/python3.6/http/client.py", line 1265, in _send_request
self.putrequest(method, url, **skips)
File "/var/lang/lib/python3.6/http/client.py", line 1127, in putrequest
raise InvalidURL(f"URL can't contain control characters. {url!r} "
http.client.InvalidURL: URL can't contain control characters.
  • reply
  • like
In Saint Petersburg there is a whitespace that is breaking the URL. Meanwhile i send a request to ...Saint%20Petersburg...
  • reply
  • like
I can confirm that this is in your lamda caller, exactly here:
path = unquote(payload['path'])
Could you tell me if this is intended way to process the functions?
  • reply
  • like
can you share your code with us so we can take a closer look?
  • reply
  • like
I will ping our engineers for more info
  • reply
  • like
thanks for answering!
  • reply
  • like
as en example
from http.server import BaseHTTPRequestHandler from urllib.parse import parse_qs, urlparse
def parse_url_params(path): params = parse_qs(path) strict_params = {}
for key, value in params.items():
strict_params[key] = value[0]
return strict_params
class handler(BaseHTTPRequestHandler):
# pylint: disable=invalid-name
# pylint: disable=no-member
def do_GET(self):
# pylint: disable=invalid-name
# pylint: disable=broad-except
try:
self.send_response(200)
self.send_header('Content-type', 'application/json')
self.end_headers()
params = parse_url_params(urlparse(self.path).query)
self.wfile.write(str(params).encode('utf-8'))
except Exception as exc:
self.send_response(500)
self.send_header('Content-type', 'text/plain')
self.end_headers()
self.wfile.write(str(exc).encode('utf-8'))
  • reply
  • like
but basically any code with BaseHTTPRequestHandler will cause this error if you supply a %20 in the query of the request
  • reply
  • like

October 22, 2019 at 12:56pm
Hi Anatoly,
This looks like a bug in the /python builder. The unquote seems wrong. This should fix it:
path = payload['path']
Would you like to submit a PR to fix this bug?
Edited
  • reply
  • like
Hello .
Thanks for looking into that. Looked like a bug to me too. Thanks for reaching out. Will submit PR right now
  • reply
  • like

February 26, 2020 at 8:23pm
Hi guys. Im facing the same problems with python and '+' in the GET url query parameters. I get
URL can't contain control characters. '/user/register/Job ko' (found at least ' '): InvalidURL Traceback (most recent call last): File "/var/task/now__handler__python.py", line 61, in now_handler conn.request(method, path, headers=headers, body=request_body) File "/var/lang/lib/python3.6/http/client.py", line 1262, in request self._send_request(method, url, body, headers, encode_chunked) File "/var/lang/lib/python3.6/http/client.py", line 1273, in _send_request self.putrequest(method, url, **skips) File "/var/lang/lib/python3.6/http/client.py", line 1124, in putrequest self._validate_path(url) File "/var/lang/lib/python3.6/http/client.py", line 1215, in _validate_path raise InvalidURL(f"URL can't contain control characters. {url!r} " http.client.InvalidURL: URL can't contain control characters. '/user/register/Job ko' (found at least ' ')
Edited
  • reply
  • like
  • reply
  • like

February 27, 2020 at 1:14pm
hi guys. Any idea on this issue? . it seems that if the query params of a URL has space, it wont work. Weird and also important bug.
  • reply
  • like
  • reply
  • like
  • reply
  • like
  • reply
  • like

February 28, 2020 at 1:59pm
This has been fixed in the canary channel. Please try npm i -g [email protected] and deploy with now.
  • reply
  • like
private
This channel has been archived