Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hub
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package registry
Operate
Terraform modules
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
thomasDOTwtf
hub
Commits
864bf6bc
Commit
864bf6bc
authored
Jun 20, 2023
by
HeJ
Browse files
Options
Downloads
Patches
Plain Diff
codestyle fixes (dereferer env parsing)
parent
7cd53d94
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/hub/settings/base.py
+20
-16
20 additions, 16 deletions
src/hub/settings/base.py
with
20 additions
and
16 deletions
src/hub/settings/base.py
+
20
−
16
View file @
864bf6bc
...
...
@@ -102,6 +102,26 @@ def gen_secret_key():
return
''
.
join
([
random
.
SystemRandom
().
choice
(
SECRET_CHARSET
)
for
i
in
range
(
50
)])
# regex to match arbitrary hostnames
REGEX_HOST
=
re
.
compile
(
r
'
([\w\d-]+\.)+\w+(:\d+)?
'
)
# helper function for parsing DEREFERER_*LIST (allow hostname only, regex and https:// prefixed strings)
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
REGEX_HOST
.
fullmatch
(
item
):
target
.
append
(
'
https://
'
+
item
)
else
:
print
(
'
WARNING: failed to parse pattern
"'
,
item
,
"'
(expected hostname, url or slash-enclosed regex), skipping it
"
,
sep
=
''
)
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR
=
Path
(
__file__
).
resolve
().
parent
.
parent
...
...
@@ -528,22 +548,6 @@ PLAINUI_CONFERENCE = env('PLAINUI_CONFERENCE')
# 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
=
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')
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment