Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
LibreTranslate
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Riße, Matthias
LibreTranslate
Commits
a1244b9e
Commit
a1244b9e
authored
3 years ago
by
Piero Toffanin
Browse files
Options
Downloads
Patches
Plain Diff
Path traversal check
parent
d12c81b7
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/app.py
+9
-4
9 additions, 4 deletions
app/app.py
app/security.py
+14
-0
14 additions, 0 deletions
app/security.py
app/templates/index.html
+1
-1
1 addition, 1 deletion
app/templates/index.html
with
24 additions
and
5 deletions
app/app.py
+
9
−
4
View file @
a1244b9e
...
...
@@ -12,7 +12,7 @@ from flask_swagger_ui import get_swaggerui_blueprint
from
translatehtml
import
translate_html
from
werkzeug.utils
import
secure_filename
from
app
import
flood
,
remove_translated_files
from
app
import
flood
,
remove_translated_files
,
security
from
app.language
import
detect_languages
,
transliterate
from
.api_keys
import
Database
from
.suggestions
import
Database
as
SuggestionsDatabase
...
...
@@ -621,10 +621,15 @@ def create_app(args):
Download a translated file
"""
if
args
.
disable_files_translation
:
abort
(
403
,
description
=
"
Files translation are disabled on this server.
"
)
abort
(
400
,
description
=
"
Files translation are disabled on this server.
"
)
filepath
=
os
.
path
.
join
(
get_upload_dir
(),
filename
)
try
:
checked_filepath
=
security
.
path_traversal_check
(
filepath
,
get_upload_dir
())
if
os
.
path
.
isfile
(
checked_filepath
):
filepath
=
checked_filepath
except
security
.
SuspiciousFileOperation
:
abort
(
400
,
description
=
"
Invalid filename
"
)
return_data
=
io
.
BytesIO
()
with
open
(
filepath
,
'
rb
'
)
as
fo
:
...
...
This diff is collapsed.
Click to expand it.
app/security.py
0 → 100644
+
14
−
0
View file @
a1244b9e
import
os
class
SuspiciousFileOperation
(
Exception
):
pass
def
path_traversal_check
(
unsafe_path
,
known_safe_path
):
known_safe_path
=
os
.
path
.
abspath
(
known_safe_path
)
unsafe_path
=
os
.
path
.
abspath
(
unsafe_path
)
if
(
os
.
path
.
commonprefix
([
known_safe_path
,
unsafe_path
])
!=
known_safe_path
):
raise
SuspiciousFileOperation
(
"
{} is not safe
"
.
format
(
unsafe_path
))
# Passes the check
return
unsafe_path
\ No newline at end of file
This diff is collapsed.
Click to expand it.
app/templates/index.html
+
1
−
1
View file @
a1244b9e
...
...
@@ -175,7 +175,7 @@
<div
class=
"row"
v-if=
"translationType === 'files'"
>
<div
class=
"file-dropzone"
>
<div
v-if=
"inputFile === false"
class=
"dropzone-content"
>
<span>
Supported file format: [[ supportedFilesFormatFormatted ]]
</span>
<span>
Supported file format
s
: [[ supportedFilesFormatFormatted ]]
</span>
<form
action=
"#"
>
<div
class=
"file-field input-field"
>
<div
class=
"btn"
>
...
...
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
register
or
sign in
to comment