-
Notifications
You must be signed in to change notification settings - Fork 184
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
escape DN attribute values #4117
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,6 @@ | ||
Bugfix: Escape DN attribute value | ||
|
||
Escaped the DN attribute value on creating users and groups. | ||
|
||
|
||
https://github.com/owncloud/ocis/pull/4117 |
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,13 @@ | ||
package ldap_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestLdap(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Ldap Suite") | ||
} |
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,25 @@ | ||
package ldap_test | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"github.com/owncloud/ocis/v2/ocis-pkg/ldap" | ||
) | ||
|
||
var _ = Describe("ldap", func() { | ||
DescribeTable("EscapeDNAttributeValue should escape special characters", | ||
func(input, expected string) { | ||
escaped := ldap.EscapeDNAttributeValue(input) | ||
Expect(escaped).To(Equal(expected)) | ||
}, | ||
Entry("normal dn", "foobar", "foobar"), | ||
Entry("including comma", "foo,bar", "foo\\,bar"), | ||
Entry("including equals", "foo=bar", "foo\\=bar"), | ||
Entry("beginning with number sign", "#foobar", "\\#foobar"), | ||
Entry("beginning with space", " foobar", "\\ foobar"), | ||
Entry("only one space", " ", "\\ "), | ||
Entry("two spaces", " ", "\\ \\ "), | ||
Entry("ending with space", "foobar ", "foobar\\ "), | ||
Entry("containing multiple special chars", `f+o>o,b<a;r="\00"`, `f\+o\>o\,b\<a\;r\=\\"\\00\\"`), | ||
) | ||
}) |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I am reading rfc4514 correctly the null byte as to be escaped as
\00
which would be:Only
' ', '"', '#', '+', ',', ';', '<', '=', '>', or '\'
can be escape by prepending a backslashThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a tricky one but I argue that this is correct.
The left side is the "search" pattern so we are looking for the null byte which as a string is represented like
\000 (octal) or \x00 (hex)
both forms result in the null byte.Now the right (replace) part is actually to things. First
\\
and second\000
Together it results in\00
but in string form it needs to be typed as it is above.https://go.dev/play/p/IzDMsTunmaj
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am still not fully convinced 🙂 what I am referring to is this sentence of the RFC:
So the null Byte (
\000
in go) needs to be translated into the string\00
(backslash + two hex digits representing the single octet of the "null character"). As the backslash needs to be escaped in go we get\\00
. (At least if I am not missing anything obvious)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, after researching a bit I found that you are right.
This also means that the python library I took inspiration from must be wrong 😅 : https://github.com/python-ldap/python-ldap/blob/44a593d1c55a007a43fcf30d2b027ac910ea1b96/Lib/ldap/dn.py#L31
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see now why this doesn't make sense. :D