Skip to content

Commit b5be576

Browse files
docs: add documentation to the changes
1 parent 55184a9 commit b5be576

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

request.go

+14-7
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,28 @@ func getReferral(err error, packet *ber.Packet) (referral string) {
7979
return ""
8080
}
8181

82-
children := len(packet.Children[1].Children)
83-
84-
if children == 0 || (packet.Children[1].TagType != ber.TypeConstructed || packet.Children[1].ClassType != ber.ClassApplication) {
82+
// The packet Tag itself (of child 2) is generally a ber.TagObjectDescriptor with referrals however OpenLDAP
83+
// seemingly returns a ber.Tag.GeneralizedTime. Every currently tested LDAP server which returns referrals returns
84+
// an ASN.1 BER packet with the Type of ber.TypeConstructed and Class of ber.ClassApplication however. Thus this
85+
// check expressly checks these fields instead.
86+
//
87+
// Related Issues:
88+
// - https://github.com/authelia/authelia/issues/4199 (downstream)
89+
if len(packet.Children[1].Children) == 0 || (packet.Children[1].TagType != ber.TypeConstructed || packet.Children[1].ClassType != ber.ClassApplication) {
8590
return ""
8691
}
8792

8893
var ok bool
8994

90-
for i := 0; i < children; i++ {
91-
if (packet.Children[1].Children[i].Tag != ber.TagBitString && packet.Children[1].Children[i].Tag != ber.TagPrintableString) ||
92-
packet.Children[1].Children[i].TagType != ber.TypeConstructed || packet.Children[1].Children[i].ClassType != ber.ClassContext {
95+
for _, child := range packet.Children[1].Children {
96+
// The referral URI itself should be contained within a child which has a Tag of ber.BitString or
97+
// ber.TagPrintableString, and the Type of ber.TypeConstructed and the Class of ClassContext. As soon as any of
98+
// these conditions is not true we can skip this child.
99+
if (child.Tag != ber.TagBitString && child.Tag != ber.TagPrintableString) || child.TagType != ber.TypeConstructed || child.ClassType != ber.ClassContext {
93100
continue
94101
}
95102

96-
if referral, ok = packet.Children[1].Children[i].Children[0].Value.(string); ok {
103+
if referral, ok = child.Children[0].Value.(string); ok {
97104
return referral
98105
}
99106
}

v3/request.go

+14-7
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,28 @@ func getReferral(err error, packet *ber.Packet) (referral string) {
7979
return ""
8080
}
8181

82-
children := len(packet.Children[1].Children)
83-
84-
if children == 0 || (packet.Children[1].TagType != ber.TypeConstructed || packet.Children[1].ClassType != ber.ClassApplication) {
82+
// The packet Tag itself (of child 2) is generally a ber.TagObjectDescriptor with referrals however OpenLDAP
83+
// seemingly returns a ber.Tag.GeneralizedTime. Every currently tested LDAP server which returns referrals returns
84+
// an ASN.1 BER packet with the Type of ber.TypeConstructed and Class of ber.ClassApplication however. Thus this
85+
// check expressly checks these fields instead.
86+
//
87+
// Related Issues:
88+
// - https://github.com/authelia/authelia/issues/4199 (downstream)
89+
if len(packet.Children[1].Children) == 0 || (packet.Children[1].TagType != ber.TypeConstructed || packet.Children[1].ClassType != ber.ClassApplication) {
8590
return ""
8691
}
8792

8893
var ok bool
8994

90-
for i := 0; i < children; i++ {
91-
if (packet.Children[1].Children[i].Tag != ber.TagBitString && packet.Children[1].Children[i].Tag != ber.TagPrintableString) ||
92-
packet.Children[1].Children[i].TagType != ber.TypeConstructed || packet.Children[1].Children[i].ClassType != ber.ClassContext {
95+
for _, child := range packet.Children[1].Children {
96+
// The referral URI itself should be contained within a child which has a Tag of ber.BitString or
97+
// ber.TagPrintableString, and the Type of ber.TypeConstructed and the Class of ClassContext. As soon as any of
98+
// these conditions is not true we can skip this child.
99+
if (child.Tag != ber.TagBitString && child.Tag != ber.TagPrintableString) || child.TagType != ber.TypeConstructed || child.ClassType != ber.ClassContext {
93100
continue
94101
}
95102

96-
if referral, ok = packet.Children[1].Children[i].Children[0].Value.(string); ok {
103+
if referral, ok = child.Children[0].Value.(string); ok {
97104
return referral
98105
}
99106
}

0 commit comments

Comments
 (0)