Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DataCatalog
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
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
eFlows4HPC WP2
DataCatalog
Commits
11d4f39c
Commit
11d4f39c
authored
3 years ago
by
Christian Boettcher
Browse files
Options
Downloads
Patches
Plain Diff
add verification of oid format
parent
5ec39719
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
apiserver/main.py
+7
-1
7 additions, 1 deletion
apiserver/main.py
apiserver/storage/JsonFileStorageAdapter.py
+11
-0
11 additions, 0 deletions
apiserver/storage/JsonFileStorageAdapter.py
apiserver/storage/__init__.py
+1
-1
1 addition, 1 deletion
apiserver/storage/__init__.py
with
19 additions
and
2 deletions
apiserver/main.py
+
7
−
1
View file @
11d4f39c
...
...
@@ -15,7 +15,7 @@ from .config import ApiserverSettings
from
.security
import
(
ACCESS_TOKEN_EXPIRES_MINUTES
,
JsonDBInterface
,
Token
,
User
,
authenticate_user
,
create_access_token
,
get_current_user
)
from
.storage
import
JsonFileStorageAdapter
,
LocationData
,
LocationDataType
from
.storage
import
JsonFileStorageAdapter
,
LocationData
,
LocationDataType
,
verify_oid
class
ReservedPaths
(
str
,
Enum
):
...
...
@@ -86,6 +86,8 @@ async def list_datasets(location_data_type: LocationDataType):
@app.get
(
"
/{location_data_type}/{dataset_id}
"
,
response_model
=
LocationData
)
async
def
get_specific_dataset
(
location_data_type
:
LocationDataType
,
dataset_id
:
str
):
"""
returns all information about a specific dataset, identified by id
"""
if
not
verify_oid
(
dataset_id
):
raise
HTTPException
(
status_code
=
400
,
detail
=
"
Invalid OID format!
"
)
return
adapter
.
get_details
(
location_data_type
,
dataset_id
)
@app.post
(
"
/{location_data_type}
"
)
...
...
@@ -101,6 +103,8 @@ async def update_specific_dataset(location_data_type: LocationDataType,
dataset_id
:
str
,
dataset
:
LocationData
,
user
:
User
=
Depends
(
my_user
)):
"""
update the information about a specific dataset, identified by id
"""
if
not
verify_oid
(
dataset_id
):
raise
HTTPException
(
status_code
=
400
,
detail
=
"
Invalid OID format!
"
)
return
adapter
.
update_details
(
location_data_type
,
dataset_id
,
dataset
,
user
.
username
)
...
...
@@ -109,6 +113,8 @@ async def delete_specific_dataset(location_data_type: LocationDataType,
dataset_id
:
str
,
user
:
str
=
Depends
(
my_user
)):
"""
delete a specific dataset
"""
if
not
verify_oid
(
dataset_id
):
raise
HTTPException
(
status_code
=
400
,
detail
=
"
Invalid OID format!
"
)
# TODO: 404 is the right answer? 204 could also be the right one
return
adapter
.
delete
(
location_data_type
,
dataset_id
,
user
.
username
)
...
...
This diff is collapsed.
Click to expand it.
apiserver/storage/JsonFileStorageAdapter.py
+
11
−
0
View file @
11d4f39c
...
...
@@ -24,6 +24,17 @@ def get_unique_id(path: str) -> str:
oid
=
str
(
uuid
.
uuid4
())
return
oid
def
verify_oid
(
oid
:
str
,
version
=
4
):
"""
Ensure thatthe oid is formatted as a valid oid (i.e. UUID v4).
If it isn
'
t, the corresponding request could theoretically be an attempted path traversal attack (or a regular typo).
"""
try
:
uuid_obj
=
uuid
.
UUID
(
oid
,
version
=
version
)
except
:
return
False
return
str
(
uuid_obj
)
==
oid
class
JsonFileStorageAdapter
(
AbstractLocationDataStorageAdapter
):
"""
This stores LocationData via the StoredData Object as json files
...
...
This diff is collapsed.
Click to expand it.
apiserver/storage/__init__.py
+
1
−
1
View file @
11d4f39c
from
.JsonFileStorageAdapter
import
JsonFileStorageAdapter
from
.JsonFileStorageAdapter
import
JsonFileStorageAdapter
,
verify_oid
from
.LocationStorage
import
LocationDataType
,
LocationData
,
AbstractLocationDataStorageAdapter
\ No newline at end of file
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