-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
openid: Adds a validator used to validate OIDC parameters (#266)
The validator, for now, validates the prompt parameter of OIDC requests.
- Loading branch information
Showing
13 changed files
with
275 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* Copyright © 2017-2018 Aeneas Rekkas <[email protected]> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* @author Aeneas Rekkas <[email protected]> | ||
* @Copyright 2017-2018 Aeneas Rekkas <[email protected]> | ||
* @license Apache-2.0 | ||
* | ||
*/ | ||
|
||
package openid | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ory/fosite" | ||
"github.com/ory/go-convenience/stringslice" | ||
"github.com/ory/go-convenience/stringsx" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
type OpenIDConnectRequestValidator struct { | ||
AllowedPrompt []string | ||
} | ||
|
||
func NewOpenIDConnectRequestValidator(prompt []string) *OpenIDConnectRequestValidator { | ||
if len(prompt) == 0 { | ||
prompt = []string{"login", "none", "consent", "select_account"} | ||
} | ||
|
||
return &OpenIDConnectRequestValidator{ | ||
AllowedPrompt: prompt, | ||
} | ||
} | ||
|
||
func (v *OpenIDConnectRequestValidator) ValidatePrompt(req fosite.AuthorizeRequester) error { | ||
// prompt is case sensitive! | ||
prompt := stringsx.Splitx(req.GetRequestForm().Get("prompt"), " ") | ||
|
||
if req.GetClient().IsPublic() { | ||
// Threat: Malicious Client Obtains Existing Authorization by Fraud | ||
// https://tools.ietf.org/html/rfc6819#section-4.2.3 | ||
// | ||
// Authorization servers should not automatically process repeat | ||
// authorizations to public clients unless the client is validated | ||
// using a pre-registered redirect URI | ||
|
||
// Client Impersonation | ||
// https://tools.ietf.org/html/rfc8252#section-8.6# | ||
// | ||
// As stated in Section 10.2 of OAuth 2.0 [RFC6749], the authorization | ||
// server SHOULD NOT process authorization requests automatically | ||
// without user consent or interaction, except when the identity of the | ||
// client can be assured. This includes the case where the user has | ||
// previously approved an authorization request for a given client id -- | ||
// unless the identity of the client can be proven, the request SHOULD | ||
// be processed as if no previous request had been approved. | ||
|
||
// To make sure that we are not vulnerable to this type of attack, we will always require consent for public | ||
// clients. | ||
|
||
// If prompt is none - meaning that no consent should be requested, we must terminate with an error. | ||
if stringslice.Has(prompt, "none") { | ||
return errors.WithStack(fosite.ErrConsentRequired.WithDebug("OAuth 2.0 Client is marked public and requires end-user consent, but prompt=none was requested")) | ||
} | ||
} | ||
|
||
if !isWhitelisted(prompt, v.AllowedPrompt) { | ||
return errors.WithStack(fosite.ErrInvalidRequest.WithDebug(fmt.Sprintf(`Used unknown value "%s" for prompt parameter`, prompt))) | ||
} | ||
|
||
if stringslice.Has(prompt, "none") && len(prompt) > 1 { | ||
// If this parameter contains none with any other value, an error is returned. | ||
return errors.WithStack(fosite.ErrInvalidRequest.WithDebug("Parameter prompt was set to none, but contains other values as well which is not allowed")) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func isWhitelisted(items []string, whiteList []string) bool { | ||
for _, item := range items { | ||
if !stringslice.Has(whiteList, item) { | ||
return false | ||
} | ||
} | ||
return true | ||
} |
Oops, something went wrong.