Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dex
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
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
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 GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hdacloud
dex
Commits
8fd69c16
Commit
8fd69c16
authored
3 years ago
by
Bob Callaway
Browse files
Options
Downloads
Patches
Plain Diff
correctly handle path escaping for connector IDs
Signed-off-by:
Bob Callaway
<
bob.callaway@gmail.com
>
parent
ff6e7c76
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
server/handlers.go
+22
-6
22 additions, 6 deletions
server/handlers.go
server/handlers_test.go
+9
-0
9 additions, 0 deletions
server/handlers_test.go
server/server.go
+1
-1
1 addition, 1 deletion
server/server.go
with
32 additions
and
7 deletions
server/handlers.go
+
22
−
6
View file @
8fd69c16
...
@@ -153,7 +153,7 @@ func (s *Server) handleAuthorization(w http.ResponseWriter, r *http.Request) {
...
@@ -153,7 +153,7 @@ func (s *Server) handleAuthorization(w http.ResponseWriter, r *http.Request) {
if
connectorID
!=
""
{
if
connectorID
!=
""
{
for
_
,
c
:=
range
connectors
{
for
_
,
c
:=
range
connectors
{
if
c
.
ID
==
connectorID
{
if
c
.
ID
==
connectorID
{
connURL
.
Path
=
s
.
absPath
(
"/auth"
,
c
.
ID
)
connURL
.
Path
=
s
.
absPath
(
"/auth"
,
url
.
PathEscape
(
c
.
ID
)
)
http
.
Redirect
(
w
,
r
,
connURL
.
String
(),
http
.
StatusFound
)
http
.
Redirect
(
w
,
r
,
connURL
.
String
(),
http
.
StatusFound
)
return
return
}
}
...
@@ -163,13 +163,13 @@ func (s *Server) handleAuthorization(w http.ResponseWriter, r *http.Request) {
...
@@ -163,13 +163,13 @@ func (s *Server) handleAuthorization(w http.ResponseWriter, r *http.Request) {
}
}
if
len
(
connectors
)
==
1
&&
!
s
.
alwaysShowLogin
{
if
len
(
connectors
)
==
1
&&
!
s
.
alwaysShowLogin
{
connURL
.
Path
=
s
.
absPath
(
"/auth"
,
connectors
[
0
]
.
ID
)
connURL
.
Path
=
s
.
absPath
(
"/auth"
,
url
.
PathEscape
(
connectors
[
0
]
.
ID
)
)
http
.
Redirect
(
w
,
r
,
connURL
.
String
(),
http
.
StatusFound
)
http
.
Redirect
(
w
,
r
,
connURL
.
String
(),
http
.
StatusFound
)
}
}
connectorInfos
:=
make
([]
connectorInfo
,
len
(
connectors
))
connectorInfos
:=
make
([]
connectorInfo
,
len
(
connectors
))
for
index
,
conn
:=
range
connectors
{
for
index
,
conn
:=
range
connectors
{
connURL
.
Path
=
s
.
absPath
(
"/auth"
,
conn
.
ID
)
connURL
.
Path
=
s
.
absPath
(
"/auth"
,
url
.
PathEscape
(
conn
.
ID
)
)
connectorInfos
[
index
]
=
connectorInfo
{
connectorInfos
[
index
]
=
connectorInfo
{
ID
:
conn
.
ID
,
ID
:
conn
.
ID
,
Name
:
conn
.
Name
,
Name
:
conn
.
Name
,
...
@@ -200,7 +200,13 @@ func (s *Server) handleConnectorLogin(w http.ResponseWriter, r *http.Request) {
...
@@ -200,7 +200,13 @@ func (s *Server) handleConnectorLogin(w http.ResponseWriter, r *http.Request) {
return
return
}
}
connID
:=
mux
.
Vars
(
r
)[
"connector"
]
connID
,
err
:=
url
.
PathUnescape
(
mux
.
Vars
(
r
)[
"connector"
])
if
err
!=
nil
{
s
.
logger
.
Errorf
(
"Failed to parse connector: %v"
,
err
)
s
.
renderError
(
r
,
w
,
http
.
StatusBadRequest
,
"Requested resource does not exist"
)
return
}
conn
,
err
:=
s
.
getConnector
(
connID
)
conn
,
err
:=
s
.
getConnector
(
connID
)
if
err
!=
nil
{
if
err
!=
nil
{
s
.
logger
.
Errorf
(
"Failed to get connector: %v"
,
err
)
s
.
logger
.
Errorf
(
"Failed to get connector: %v"
,
err
)
...
@@ -316,7 +322,12 @@ func (s *Server) handlePasswordLogin(w http.ResponseWriter, r *http.Request) {
...
@@ -316,7 +322,12 @@ func (s *Server) handlePasswordLogin(w http.ResponseWriter, r *http.Request) {
return
return
}
}
if
connID
:=
mux
.
Vars
(
r
)[
"connector"
];
connID
!=
""
&&
connID
!=
authReq
.
ConnectorID
{
connID
,
err
:=
url
.
PathUnescape
(
mux
.
Vars
(
r
)[
"connector"
])
if
err
!=
nil
{
s
.
logger
.
Errorf
(
"Failed to parse connector: %v"
,
err
)
s
.
renderError
(
r
,
w
,
http
.
StatusBadRequest
,
"Requested resource does not exist"
)
return
}
else
if
connID
!=
""
&&
connID
!=
authReq
.
ConnectorID
{
s
.
logger
.
Errorf
(
"Connector mismatch: authentication started with id %q, but password login for id %q was triggered"
,
authReq
.
ConnectorID
,
connID
)
s
.
logger
.
Errorf
(
"Connector mismatch: authentication started with id %q, but password login for id %q was triggered"
,
authReq
.
ConnectorID
,
connID
)
s
.
renderError
(
r
,
w
,
http
.
StatusInternalServerError
,
"Requested resource does not exist."
)
s
.
renderError
(
r
,
w
,
http
.
StatusInternalServerError
,
"Requested resource does not exist."
)
return
return
...
@@ -401,7 +412,12 @@ func (s *Server) handleConnectorCallback(w http.ResponseWriter, r *http.Request)
...
@@ -401,7 +412,12 @@ func (s *Server) handleConnectorCallback(w http.ResponseWriter, r *http.Request)
return
return
}
}
if
connID
:=
mux
.
Vars
(
r
)[
"connector"
];
connID
!=
""
&&
connID
!=
authReq
.
ConnectorID
{
connID
,
err
:=
url
.
PathUnescape
(
mux
.
Vars
(
r
)[
"connector"
])
if
err
!=
nil
{
s
.
logger
.
Errorf
(
"Failed to get connector with id %q : %v"
,
authReq
.
ConnectorID
,
err
)
s
.
renderError
(
r
,
w
,
http
.
StatusInternalServerError
,
"Requested resource does not exist."
)
return
}
else
if
connID
!=
""
&&
connID
!=
authReq
.
ConnectorID
{
s
.
logger
.
Errorf
(
"Connector mismatch: authentication started with id %q, but callback for id %q was triggered"
,
authReq
.
ConnectorID
,
connID
)
s
.
logger
.
Errorf
(
"Connector mismatch: authentication started with id %q, but callback for id %q was triggered"
,
authReq
.
ConnectorID
,
connID
)
s
.
renderError
(
r
,
w
,
http
.
StatusInternalServerError
,
"Requested resource does not exist."
)
s
.
renderError
(
r
,
w
,
http
.
StatusInternalServerError
,
"Requested resource does not exist."
)
return
return
...
...
This diff is collapsed.
Click to expand it.
server/handlers_test.go
+
9
−
0
View file @
8fd69c16
...
@@ -254,6 +254,15 @@ func mockConnectorDataTestStorage(t *testing.T, s storage.Storage) {
...
@@ -254,6 +254,15 @@ func mockConnectorDataTestStorage(t *testing.T, s storage.Storage) {
err
=
s
.
CreateConnector
(
c1
)
err
=
s
.
CreateConnector
(
c1
)
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
c2
:=
storage
.
Connector
{
ID
:
"http://any.valid.url/"
,
Type
:
"mock"
,
Name
:
"mockURLID"
,
}
err
=
s
.
CreateConnector
(
c2
)
require
.
NoError
(
t
,
err
)
}
}
func
TestPasswordConnectorDataNotEmpty
(
t
*
testing
.
T
)
{
func
TestPasswordConnectorDataNotEmpty
(
t
*
testing
.
T
)
{
...
...
This diff is collapsed.
Click to expand it.
server/server.go
+
1
−
1
View file @
8fd69c16
...
@@ -302,7 +302,7 @@ func newServer(ctx context.Context, c Config, rotationStrategy rotationStrategy)
...
@@ -302,7 +302,7 @@ func newServer(ctx context.Context, c Config, rotationStrategy rotationStrategy)
}
}
}
}
r
:=
mux
.
NewRouter
()
r
:=
mux
.
NewRouter
()
.
SkipClean
(
true
)
.
UseEncodedPath
()
handle
:=
func
(
p
string
,
h
http
.
Handler
)
{
handle
:=
func
(
p
string
,
h
http
.
Handler
)
{
r
.
Handle
(
path
.
Join
(
issuerURL
.
Path
,
p
),
instrumentHandlerCounter
(
p
,
h
))
r
.
Handle
(
path
.
Join
(
issuerURL
.
Path
,
p
),
instrumentHandlerCounter
(
p
,
h
))
}
}
...
...
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