Skip to content

Commit

Permalink
pam/gdm/conversation: Show the Poll response if non-empty
Browse files Browse the repository at this point in the history
In case the gdm data poll response has content, it's still something we
want to show, even though we should sanitize the value when it contains
the challenge secret

Fixes: 40fa85d
  • Loading branch information
3v1n0 committed Oct 2, 2024
1 parent fa276dd commit 600dff6
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pam/internal/gdm/conversation.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import (
"context"
"errors"
"fmt"
"regexp"
"sync/atomic"

"github.com/msteinert/pam/v2"
"github.com/ubuntu/authd/internal/log"
)

var conversations atomic.Int32
var challengeRegex = regexp.MustCompile(`"challenge"\s*:\s*"(?:[^"\\]|\\.)*"`)

// ConversationInProgress checks if conversations are currently active.
func ConversationInProgress() bool {
Expand Down Expand Up @@ -63,9 +65,16 @@ func SendData(pamMTx pam.ModuleTransaction, d *Data) (*Data, error) {
}

gdmData, err := NewDataFromJSON(jsonValue)
// Log unless it's a poll, which are so frequently that it would be
// Log unless it's an empty poll, which are so frequently that it would be
// too verbose to log them.
if d.Type != DataType_poll {
if gdmData.Type == DataType_pollResponse && len(gdmData.GetPollResponse()) == 0 {
jsonValue = nil
}
if log.IsLevelEnabled(log.DebugLevel) && jsonValue != nil &&
gdmData != nil && gdmData.Type == DataType_pollResponse {
jsonValue = challengeRegex.ReplaceAll(jsonValue, []byte(`"challenge":"**************"`))
}
if jsonValue != nil {
log.Debugf(context.TODO(), "Got from GDM: %s", jsonValue)
}
if err != nil {
Expand Down

0 comments on commit 600dff6

Please sign in to comment.