Merged in feature/HTTPASTE-46/view (pull request #51)
fix(router): add SSL exemption for Tor hidden services
This commit is contained in:
commit
0658edd9b9
3 changed files with 18 additions and 4 deletions
|
|
@ -38,6 +38,6 @@ services:
|
|||
dockerfile: Dockerfile
|
||||
volumes:
|
||||
- ./tor/etc/tor/torrc:/etc/tor/torrc
|
||||
- ./tor/var/lib/tor/hidden_service:./tor/var/lib/tor/hidden_service
|
||||
- ./tor/var/lib/tor/hidden_service:/tor/var/lib/tor/hidden_service
|
||||
volumes:
|
||||
system-shared:
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ from httpaste.model import Config as ModelConfig
|
|||
from httpaste.backend import get_backend_config
|
||||
from httpaste.backend import Config as BackendConfig
|
||||
from httpaste.helper.config import get_configparser, CONFIGPATH_ENVIRON
|
||||
from httpaste.helper.url import url_upgrade_to_https
|
||||
from httpaste.helper.url import url_upgrade_to_https, url_has_tld
|
||||
from httpaste.helper.http import (
|
||||
BadRequestError,
|
||||
ForbiddenError,
|
||||
|
|
@ -247,7 +247,7 @@ def get_flask_app(config: Config) -> FlaskApp:
|
|||
|
||||
https_url = url_upgrade_to_https(request.url, config.server.ssl_port)
|
||||
|
||||
if https_url != request.url:
|
||||
if https_url != request.url and not url_has_tld(request._view, 'onion'):
|
||||
|
||||
request._view['before_request__ssl_url'] = https_url
|
||||
|
||||
|
|
|
|||
|
|
@ -37,4 +37,18 @@ def url_upgrade_to_https(url: str, port: Optional[int] = 443):
|
|||
|
||||
urlcomps = urlcomps._replace(netloc=netloc)
|
||||
|
||||
return urlcomps.geturl()
|
||||
return urlcomps.geturl()
|
||||
|
||||
|
||||
def url_has_tld(url:str, tld:str):
|
||||
|
||||
urlcomps = urlparse(url)
|
||||
|
||||
hostname = urlcomps.netloc.rsplit(':', 1)[0]
|
||||
|
||||
hostname_levels = hostname.rsplit('.', 1)
|
||||
|
||||
if len(hostname_levels) > 1 and hostname_levels[-1:][0] == tld:
|
||||
return True
|
||||
|
||||
return False
|
||||
Loading…
Add table
Add a link
Reference in a new issue