Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
CloWM S3-Proxy Service
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
Looking for advice? Join the
Matrix channel for GitLab users in Bielefeld
!
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Computational Metagenomics
CloWM
CloWM S3-Proxy Service
Commits
1718da56
Verified
Commit
1718da56
authored
1 year ago
by
Daniel Göbel
Browse files
Options
Downloads
Patches
Plain Diff
Improve regex to catch forbidden bucket names
#64
parent
4ebc2fab
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/api/dependencies.py
+1
-1
1 addition, 1 deletion
app/api/dependencies.py
app/main.py
+3
-1
3 additions, 1 deletion
app/main.py
app/schemas/bucket.py
+4
-3
4 additions, 3 deletions
app/schemas/bucket.py
with
8 additions
and
5 deletions
app/api/dependencies.py
+
1
−
1
View file @
1718da56
...
...
@@ -254,7 +254,7 @@ async def get_current_bucket(
bucket : clowmdb.models.Bucket
Bucket with the given name.
"""
bucket
=
await
CRUDBucket
.
get
(
db
,
bucket_name
.
split
(
"
:
"
)[
-
1
]
)
bucket
=
await
CRUDBucket
.
get
(
db
,
bucket_name
)
if
bucket
is
None
:
raise
HTTPException
(
status_code
=
status
.
HTTP_404_NOT_FOUND
,
detail
=
"
Bucket not found
"
)
return
bucket
...
...
This diff is collapsed.
Click to expand it.
app/main.py
+
3
−
1
View file @
1718da56
...
...
@@ -63,7 +63,9 @@ if settings.OTLP_GRPC_ENDPOINT is not None and len(settings.OTLP_GRPC_ENDPOINT)
return
await
request_validation_exception_handler
(
request
,
exc
)
FastAPIInstrumentor
.
instrument_app
(
app
,
excluded_urls
=
"
health
"
,
tracer_provider
=
trace
.
get_tracer_provider
())
FastAPIInstrumentor
.
instrument_app
(
app
,
excluded_urls
=
"
health,docs,openapi.json
"
,
tracer_provider
=
trace
.
get_tracer_provider
()
)
# CORS Settings for the API
app
.
add_middleware
(
...
...
This diff is collapsed.
Click to expand it.
app/schemas/bucket.py
+
4
−
3
View file @
1718da56
...
...
@@ -4,7 +4,7 @@ from typing import Optional
from
clowmdb.models
import
Bucket
from
pydantic
import
BaseModel
,
ConfigDict
,
Field
,
field_validator
ip_regex
=
re
.
compile
(
r
"
^(
(2(5[0-5]|[0-4]\d)|[01]?\d{1,2})\.){3}(2(5[0-5]|[0-4]\d)|[01]?\d{1,2})
$
"
)
ip_
like_
regex
=
re
.
compile
(
r
"
^(
\d+\.){3}\d+
$
"
)
class
_BaseBucket
(
BaseModel
):
...
...
@@ -18,7 +18,8 @@ class _BaseBucket(BaseModel):
description
=
"
Name of the bucket
"
,
min_length
=
3
,
max_length
=
63
,
pattern
=
r
"
^[a-z\d][a-z\d.-]{1,61}[a-z\d]$
"
,
pattern
=
r
"
^([a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$
"
,
# https://docs.ceph.com/en/latest/radosgw/s3/bucketops/#constraints
)
description
:
str
=
Field
(
...,
...
...
@@ -31,7 +32,7 @@ class _BaseBucket(BaseModel):
@field_validator
(
"
name
"
)
@classmethod
def
name_is_not_an_ip_address
(
cls
,
name
:
str
)
->
str
:
if
ip_regex
.
search
(
name
):
if
ip_
like_
regex
.
search
(
name
):
raise
ValueError
(
"
no IP address as bucket name
"
)
return
name
...
...
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