From fa7255e09192091ae185d131a0eadfd3906ffd24 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 9 Oct 2019 10:42:23 +0100 Subject: [PATCH 1/2] Encode hashes correctly in proxied requests This is a very disgusting fix, but it works. Fixes https://github.com/matrix-org/pantalaimon/issues/21 --- pantalaimon/daemon.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pantalaimon/daemon.py b/pantalaimon/daemon.py index f6df15b..6fab5b6 100755 --- a/pantalaimon/daemon.py +++ b/pantalaimon/daemon.py @@ -455,6 +455,10 @@ class ProxyDaemon: path = request.path method = request.method + # This is very much a dirty hack, but it is fine for now + if "#" in path: + path = path.replace("#", "%23") + headers = CIMultiDict(request.headers) headers.pop("Host", None) From d030863245d6482b162c51cd56f356b11fd6c926 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 9 Oct 2019 12:41:03 +0100 Subject: [PATCH 2/2] Use urllib instead of magic replace --- pantalaimon/daemon.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pantalaimon/daemon.py b/pantalaimon/daemon.py index 6fab5b6..b5b3a1f 100755 --- a/pantalaimon/daemon.py +++ b/pantalaimon/daemon.py @@ -15,6 +15,7 @@ import asyncio import json import os +import urllib.parse from json import JSONDecodeError from typing import Any, Dict @@ -452,13 +453,9 @@ class ProxyDaemon: assert session - path = request.path + path = urllib.parse.quote(request.path) # re-encode path stuff like room aliases method = request.method - # This is very much a dirty hack, but it is fine for now - if "#" in path: - path = path.replace("#", "%23") - headers = CIMultiDict(request.headers) headers.pop("Host", None)