Skip to content

Commit

Permalink
providers/proxy: use hashed session as sid
Browse files Browse the repository at this point in the history
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
  • Loading branch information
BeryJu committed Dec 22, 2023
1 parent 5b9515d commit cccb70f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion authentik/providers/proxy/tasks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""proxy provider tasks"""
from hashlib import sha256

from asgiref.sync import async_to_sync
from channels.layers import get_channel_layer
from django.db import DatabaseError, InternalError, ProgrammingError
Expand All @@ -23,13 +25,14 @@ def proxy_set_defaults():
def proxy_on_logout(session_id: str):
"""Update outpost instances connected to a single outpost"""
layer = get_channel_layer()
hashed_session_id = sha256(session_id.encode("ascii")).hexdigest()

Check warning on line 28 in authentik/providers/proxy/tasks.py

View check run for this annotation

Codecov / codecov/patch

authentik/providers/proxy/tasks.py#L28

Added line #L28 was not covered by tests
for outpost in Outpost.objects.filter(type=OutpostType.PROXY):
group = OUTPOST_GROUP % {"outpost_pk": str(outpost.pk)}
async_to_sync(layer.group_send)(
group,
{
"type": "event.provider.specific",
"sub_type": "logout",
"session_id": session_id,
"session_id": hashed_session_id,
},
)
2 changes: 1 addition & 1 deletion blueprints/system/providers-proxy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ entries:
# This mapping is used by the authentik proxy. It passes extra user attributes,
# which are used for example for the HTTP-Basic Authentication mapping.
return {
"sid": request.http_request.session.session_key,
"sid": token.session_id,
"ak_proxy": {
"user_attributes": request.user.group_attributes(request),
"is_superuser": request.user.is_superuser,
Expand Down
1 change: 1 addition & 0 deletions internal/outpost/proxyv2/ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func (ps *ProxyServer) handleWSMessage(ctx context.Context, args map[string]inte
switch msg.SubType {
case WSProviderSubTypeLogout:
for _, p := range ps.apps {
ps.log.WithField("provider", p.Host).Debug("Logging out")
err := p.Logout(ctx, func(c application.Claims) bool {
return c.Sid == msg.SessionID
})
Expand Down

0 comments on commit cccb70f

Please sign in to comment.