Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consent: Restrict fc & bc logout to sid parameter #1691

Merged
merged 8 commits into from
Jan 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,11 @@ workflows:
- test-e2e-mysql
- test-e2e-cockroach
- test-e2e-plugin
filters:
tags:
only: /.*/
branches:
ignore: /master/
- sdk/release:
requires:
- test
Expand Down
6 changes: 2 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ docker:
.PHONY: e2e
e2e:
make test-resetdb
export TEST_DATABASE_MYSQL='mysql://root:secret@(127.0.0.1:3444)/mysql?parseTime=true'
export TEST_DATABASE_POSTGRESQL='postgres://postgres:secret@127.0.0.1:3445/hydra?sslmode=disable'
export TEST_DATABASE_COCKROACHDB='cockroach://root@127.0.0.1:3446/defaultdb?sslmode=disable'
source ./scripts/test-env.sh
./test/e2e/circle-ci.bash memory
./test/e2e/circle-ci.bash memory-jwt
./test/e2e/circle-ci.bash postgres
Expand Down Expand Up @@ -113,4 +111,4 @@ install:
.PHONY: init
init:
GO111MODULE=on go get .
GO111MODULE=on go install github.com/ory/go-acc
GO111MODULE=on go install github.com/ory/go-acc
4 changes: 4 additions & 0 deletions client/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ func (h *Handler) List(w http.ResponseWriter, r *http.Request, ps httprouter.Par

pagination.Header(w, r.URL, n, limit, offset)

if c == nil {
c = []Client{}
}

h.r.Writer().Write(w, r, c)
}

Expand Down
80 changes: 40 additions & 40 deletions client/sql_migration_files.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions consent/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ type Manager interface {
CreateForcedObfuscatedLoginSession(ctx context.Context, session *ForcedObfuscatedLoginSession) error
GetForcedObfuscatedLoginSession(ctx context.Context, client, obfuscated string) (*ForcedObfuscatedLoginSession, error)

ListUserAuthenticatedClientsWithFrontChannelLogout(ctx context.Context, subject string) ([]client.Client, error)
ListUserAuthenticatedClientsWithBackChannelLogout(ctx context.Context, subject string) ([]client.Client, error)
ListUserAuthenticatedClientsWithFrontChannelLogout(ctx context.Context, subject, sid string) ([]client.Client, error)
ListUserAuthenticatedClientsWithBackChannelLogout(ctx context.Context, subject, sid string) ([]client.Client, error)

CreateLogoutRequest(ctx context.Context, request *LogoutRequest) error
GetLogoutRequest(ctx context.Context, challenge string) (*LogoutRequest, error)
Expand Down
21 changes: 15 additions & 6 deletions consent/manager_memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ import (
"github.com/pkg/errors"

"github.com/ory/fosite"
"github.com/ory/hydra/x"
"github.com/ory/x/pagination"

"github.com/ory/hydra/x"
)

type MemoryManager struct {
Expand Down Expand Up @@ -459,29 +460,37 @@ func (m *MemoryManager) VerifyAndInvalidateLoginRequest(ctx context.Context, ver
return nil, errors.WithStack(x.ErrNotFound)
}

func (m *MemoryManager) ListUserAuthenticatedClientsWithFrontChannelLogout(ctx context.Context, subject string) ([]client.Client, error) {
func (m *MemoryManager) ListUserAuthenticatedClientsWithFrontChannelLogout(ctx context.Context, subject, sid string) ([]client.Client, error) {
m.m["consentRequests"].RLock()
defer m.m["consentRequests"].RUnlock()

preventDupes := make(map[string]bool)
var rs []client.Client
for _, cr := range m.consentRequests {
if cr.Subject == subject && len(cr.Client.FrontChannelLogoutURI) > 0 {
if cr.Subject == subject &&
len(cr.Client.FrontChannelLogoutURI) > 0 &&
cr.LoginSessionID == sid &&
!preventDupes[cr.Client.GetID()] {

rs = append(rs, *cr.Client)
preventDupes[cr.Client.GetID()] = true
}
}

return rs, nil
}

func (m *MemoryManager) ListUserAuthenticatedClientsWithBackChannelLogout(ctx context.Context, subject string) ([]client.Client, error) {
func (m *MemoryManager) ListUserAuthenticatedClientsWithBackChannelLogout(ctx context.Context, subject, sid string) ([]client.Client, error) {
m.m["consentRequests"].RLock()
defer m.m["consentRequests"].RUnlock()

clientsMap := make(map[string]bool)

var rs []client.Client
for _, cr := range m.consentRequests {
if cr.Subject == subject && len(cr.Client.BackChannelLogoutURI) > 0 && !clientsMap[cr.Client.GetID()] {
if cr.Subject == subject &&
cr.LoginSessionID == sid &&
len(cr.Client.BackChannelLogoutURI) > 0 &&
!(clientsMap[cr.Client.GetID()]) {
rs = append(rs, *cr.Client)
clientsMap[cr.Client.GetID()] = true
}
Expand Down
12 changes: 6 additions & 6 deletions consent/manager_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,17 +518,17 @@ func (m *SQLManager) resolveHandledConsentRequests(ctx context.Context, requests
return aa, nil
}

func (m *SQLManager) ListUserAuthenticatedClientsWithFrontChannelLogout(ctx context.Context, subject string) ([]client.Client, error) {
return m.listUserAuthenticatedClients(ctx, subject, "front")
func (m *SQLManager) ListUserAuthenticatedClientsWithFrontChannelLogout(ctx context.Context, subject, sid string) ([]client.Client, error) {
return m.listUserAuthenticatedClients(ctx, subject, sid, "front")
}

func (m *SQLManager) ListUserAuthenticatedClientsWithBackChannelLogout(ctx context.Context, subject string) ([]client.Client, error) {
return m.listUserAuthenticatedClients(ctx, subject, "back")
func (m *SQLManager) ListUserAuthenticatedClientsWithBackChannelLogout(ctx context.Context, subject, sid string) ([]client.Client, error) {
return m.listUserAuthenticatedClients(ctx, subject, sid, "back")
}

func (m *SQLManager) listUserAuthenticatedClients(ctx context.Context, subject string, channel string) ([]client.Client, error) {
func (m *SQLManager) listUserAuthenticatedClients(ctx context.Context, subject, sid, channel string) ([]client.Client, error) {
var ids []string
if err := m.DB.SelectContext(ctx, &ids, m.DB.Rebind(fmt.Sprintf(`SELECT DISTINCT(c.id) FROM hydra_client as c JOIN hydra_oauth2_consent_request as r ON (c.id = r.client_id) WHERE r.subject=? AND c.%schannel_logout_uri!='' and c.%schannel_logout_uri IS NOT NULL`, channel, channel)), subject); err != nil {
if err := m.DB.SelectContext(ctx, &ids, m.DB.Rebind(fmt.Sprintf(`SELECT DISTINCT(c.id) FROM hydra_client as c JOIN hydra_oauth2_consent_request as r ON (c.id = r.client_id) WHERE r.subject=? AND c.%schannel_logout_uri!='' AND c.%schannel_logout_uri IS NOT NULL AND r.login_session_id = ?`, channel, channel)), subject, sid); err != nil {
if err == sql.ErrNoRows {
return nil, errors.WithStack(x.ErrNotFound)
}
Expand Down
Loading