Skip to content
Snippets Groups Projects
Commit 7cd53d94 authored by HeJ's avatar HeJ
Browse files

Merge branch 'fix/env_based_dereferer_config' into 'develop'

allow env-based configuration of dereferer

See merge request hub/hub!578
parents 82cccacd b731b421
Branches
Tags
No related merge requests found
......@@ -14,6 +14,7 @@ from email.utils import getaddresses
import json
import os
from pathlib import Path
import re
from django.utils.translation import gettext_lazy as _
import environ
......@@ -85,6 +86,9 @@ env = environ.FileAwareEnv(
PLAINUI_BASE_URL=(str, ''),
PLAINUI_CONFERENCE=(str, None),
PLAINUI_DEREFERER_URL=(str, '//dereferer/{quoted_target}'),
PLAINUI_DEREFERER_ALLOWLIST=(list, []),
PLAINUI_DEREFERER_COUNTLIST=(list, []),
SHIBBOLEET_WA_ROOM_ID=('str', None),
)
......@@ -522,17 +526,35 @@ PLAINUI_CONFERENCE = env('PLAINUI_CONFERENCE')
# Absolute url to use when dereferring links. Replaces `{quoted_target}` with the urlquoted target url
# If you modify this on a non-empty database you should run `manage.py rerender_markdown` to update cashed markdown that contains old urls.
PLAINUI_DEREFERER_URL = 'https://rc3.world/2021/dereferrer/{quoted_target}'
PLAINUI_DEREFERER_URL = env('PLAINUI_DEREFERER_URL')
# helper function for parsing DEREFERER_*LIST (allow hostname only, regex and https:// prefixed strings)
re_host = re.compile('([\w\d-]+\.)+\w+(:\d+)?$')
def _handle_hostpattern_list(target: list, items: list):
for item in items:
if item.startswith('/') and item.endswith('/'):
try:
target.append(re.compile('https://' + item[1:-1]))
except re.error as err:
print('WARNING: failed to parse regex pattern "', item, "', ignoring it: ", err, sep='')
elif item.startswith('https://') or item.startswith('http://'):
target.append(item)
elif re_host.match(item):
target.append('https://' + item)
else:
print('WARNING: failed to parse pattern "', item, "' (expected hostname, url or slash-enclosed regex), skipping it", sep='')
# URI patterns that are auto-allowed (never get dereferrer'd)
# Only looks at schema and host/port, so for example for the url https://rc3.world:4321/some/where/ the entry should be `'https://rc3.world'`.
# Can also be a regex, for example re.compile(r'https://.*\.rc3\.world')
# DON'T ADD TRAILING SLASHES
DEREFERRER_GLOBAL_ALLOWLIST = []
_handle_hostpattern_list(DEREFERRER_GLOBAL_ALLOWLIST, env('PLAINUI_DEREFERER_ALLOWLIST'))
# URI patterns where following outgoing links is counted in the database
# rules are the same as with DEREFERRER_GLOBAL_ALLOWLIST
DEREFERRER_COUNT_ACCESS = []
_handle_hostpattern_list(DEREFERRER_COUNT_ACCESS, env('PLAINUI_DEREFERER_COUNTLIST'))
# Shibboleet Mode: an entrypoint /shibboleet which adds the registered user to the conference and redirects to a new WA session
# ID of the WorkAdventure room which shall be used as the entrypoint in the new WA session
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment