Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
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
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chenhao Ma
core
Commits
81f3fe22
Commit
81f3fe22
authored
7 years ago
by
Megan Henning
Browse files
Options
Downloads
Patches
Plain Diff
Add param sanitation
parent
a7857094
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/handlers/reporthandler.py
+17
-5
17 additions, 5 deletions
api/handlers/reporthandler.py
api/util.py
+15
-0
15 additions, 0 deletions
api/util.py
with
32 additions
and
5 deletions
api/handlers/reporthandler.py
+
17
−
5
View file @
81f3fe22
...
...
@@ -5,6 +5,7 @@ import pymongo
from
..web
import
base
from
..
import
config
from
..
import
util
EIGHTEEN_YEARS_IN_SEC
=
18
*
365.25
*
24
*
60
*
60
...
...
@@ -30,7 +31,7 @@ class ReportHandler(base.RequestHandler):
try
:
report
=
report_class
(
self
.
request
.
params
)
except
APIReportParamsException
as
e
:
self
.
abort
(
400
,
e
.
m
sg
)
self
.
abort
(
400
,
e
.
m
essage
)
else
:
raise
NotImplementedError
(
'
Report type {} is not supported
'
.
format
(
report_type
))
...
...
@@ -48,6 +49,7 @@ class Report(object):
"""
super
(
Report
,
self
).
__init__
()
self
.
params
=
params
def
user_can_generate
(
self
,
uid
):
"""
...
...
@@ -86,7 +88,7 @@ class Report(object):
If more than one item is in the results array, throws APIReportException
"""
results
=
_get_result_list
(
output
)
results
=
Report
.
_get_result_list
(
output
)
if
len
(
results
)
==
1
:
return
results
[
0
]
...
...
@@ -431,6 +433,8 @@ class AccessLogReport(Report):
start_date
=
params
.
get
(
'
start_date
'
)
end_date
=
params
.
get
(
'
end_date
'
)
uid
=
params
.
get
(
'
user
'
)
limit
=
params
.
get
(
'
limit
'
,
100
)
if
start_date
:
start_date
=
dateutil
.
parser
.
parse
(
start_date
)
...
...
@@ -438,11 +442,19 @@ class AccessLogReport(Report):
end_date
=
dateutil
.
parser
.
parse
(
end_date
)
if
end_date
and
start_date
and
end_date
<
start_date
:
raise
APIReportParamsException
(
'
End date {} is before start date {}
'
.
format
(
end_date
,
start_date
))
if
uid
and
not
util
.
is_user_id
(
uid
):
raise
APIReportParamsException
(
'
Invalid user.
'
)
try
:
limit
=
int
(
limit
)
except
(
TypeError
,
ValueError
):
raise
APIReportParamsException
(
'
Limit must be an integer greater than 0.
'
)
if
limit
<
1
:
raise
APIReportParamsException
(
'
Limit must be an integer greater than 0.
'
)
self
.
start_date
=
start_date
self
.
end_date
=
end_date
self
.
uid
=
params
.
get
(
'
uid
'
)
self
.
limit
=
params
.
get
(
'
limit
'
,
100
)
self
.
uid
=
uid
self
.
limit
=
limit
def
user_can_generate
(
self
,
uid
):
...
...
@@ -458,7 +470,7 @@ class AccessLogReport(Report):
query
=
{}
if
self
.
uid
:
query
[
'
origin
'
]
=
{
'
_id
'
:
self
.
uid
}
query
[
'
origin
.id
'
]
=
self
.
uid
if
self
.
start_date
or
self
.
end_date
:
query
[
'
timestamp
'
]
=
{}
if
self
.
start_date
:
...
...
This diff is collapsed.
Click to expand it.
api/util.py
+
15
−
0
View file @
81f3fe22
...
...
@@ -6,6 +6,7 @@ import json
import
mimetypes
import
os
import
random
import
re
import
requests
import
string
import
uuid
...
...
@@ -84,6 +85,20 @@ def user_perm(permissions, _id, site=None):
return
perm
return
{}
def
is_user_id
(
uid
):
"""
Checks to make sure uid matches uid regex
"""
pattern
=
re
.
compile
(
'
^[0-9a-zA-Z.@_-]*$
'
)
return
bool
(
pattern
.
match
(
uid
))
def
is_group_id
(
gid
):
"""
Checks to make sure uid matches uid regex
"""
pattern
=
re
.
compile
(
'
^[0-9a-z][0-9a-z.@_-]{0,30}[0-9a-z]$
'
)
return
bool
(
pattern
.
match
(
gid
))
def
resolve_gravatar
(
email
):
"""
Given an email, returns a URL if that email has a gravatar set.
...
...
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