Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
8954559c
Commit
8954559c
authored
Feb 15, 2018
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: whitelist allowed chars for uid
parent
243b9877
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
83 additions
and
1 deletions
+83
-1
pkg/services/dashboards/dashboards.go
+5
-0
pkg/services/dashboards/dashboards_test.go
+43
-0
pkg/util/shortid_generator.go
+23
-1
pkg/util/shortid_generator_test.go
+12
-0
No files found.
pkg/services/dashboards/dashboards.go
View file @
8954559c
...
...
@@ -6,6 +6,7 @@ import (
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/util"
)
type
Repository
interface
{
...
...
@@ -52,6 +53,10 @@ func (dr *DashboardRepository) buildSaveDashboardCommand(dto *SaveDashboardDTO)
return
nil
,
models
.
ErrDashboardTitleEmpty
}
if
err
:=
util
.
VerifyUid
(
dashboard
.
Uid
);
err
!=
nil
{
return
nil
,
err
}
validateAlertsCmd
:=
alerting
.
ValidateDashboardAlertsCommand
{
OrgId
:
dto
.
OrgId
,
Dashboard
:
dashboard
,
...
...
pkg/services/dashboards/dashboards_test.go
0 → 100644
View file @
8954559c
package
dashboards
import
(
"testing"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/util"
)
func
TestDashboardsService
(
t
*
testing
.
T
)
{
bus
.
ClearBusHandlers
()
bus
.
AddHandler
(
"test"
,
func
(
cmd
*
alerting
.
ValidateDashboardAlertsCommand
)
error
{
return
nil
})
testCases
:=
[]
struct
{
Uid
string
Error
error
}{
{
Uid
:
""
,
Error
:
nil
},
{
Uid
:
"asdf90_-"
,
Error
:
nil
},
{
Uid
:
"asdf/90"
,
Error
:
util
.
ErrDashboardInvalidUid
},
{
Uid
:
"asdfghjklqwertyuiopzxcvbnmasdfghjklqwertyuiopzxcvbnmasdfghjklqwertyuiopzxcvbnm"
,
Error
:
util
.
ErrDashboardUidToLong
},
}
repo
:=
&
DashboardRepository
{}
for
_
,
tc
:=
range
testCases
{
dto
:=
&
SaveDashboardDTO
{
Dashboard
:
&
models
.
Dashboard
{
Title
:
"title"
,
Uid
:
tc
.
Uid
},
}
_
,
err
:=
repo
.
buildSaveDashboardCommand
(
dto
)
if
err
!=
tc
.
Error
{
t
.
Fatalf
(
"expected %s to return %v"
,
tc
.
Uid
,
tc
.
Error
)
}
}
}
pkg/util/shortid_generator.go
View file @
8954559c
package
util
import
(
"errors"
"regexp"
"github.com/teris-io/shortid"
)
var
allowedChars
=
shortid
.
DefaultABC
var
validUidPattern
=
regexp
.
MustCompile
(
`^[a-zA-Z0-9\-\_]*$`
)
.
MatchString
var
ErrDashboardInvalidUid
=
errors
.
New
(
"uid contains illegal characters"
)
var
ErrDashboardUidToLong
=
errors
.
New
(
"uid to long. max 40 characters"
)
func
VerifyUid
(
uid
string
)
error
{
if
len
(
uid
)
>
40
{
return
ErrDashboardUidToLong
}
if
!
validUidPattern
(
uid
)
{
return
ErrDashboardInvalidUid
}
return
nil
}
func
init
()
{
gen
,
_
:=
shortid
.
New
(
1
,
shortid
.
DefaultABC
,
1
)
gen
,
_
:=
shortid
.
New
(
1
,
allowedChars
,
1
)
shortid
.
SetDefault
(
gen
)
}
...
...
pkg/util/shortid_generator_test.go
0 → 100644
View file @
8954559c
package
util
import
"testing"
func
TestAllowedCharMatchesUidPattern
(
t
*
testing
.
T
)
{
for
_
,
c
:=
range
allowedChars
{
err
:=
VerifyUid
(
string
(
c
))
if
err
!=
nil
{
t
.
Fatalf
(
"charset for creating new shortids contains chars not present in uid pattern"
)
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment