-
Notifications
You must be signed in to change notification settings - Fork 732
fix: normalize CRLF line endings in .htpasswd to prevent xDS rejection #8567
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2013,6 +2013,11 @@ func (t *Translator) buildBasicAuth( | |
| usersSecret.Namespace, usersSecret.Name) | ||
| } | ||
|
|
||
| // Normalize CRLF to LF to handle .htpasswd files generated on Windows. | ||
| // Without this, the \r character gets included in the hash string, causing | ||
| // Envoy to reject the xDS config with "invalid SHA hash length" errors. | ||
| usersSecretBytes = []byte(strings.ReplaceAll(string(usersSecretBytes), "\r\n", "\n")) | ||
|
|
||
|
Comment on lines
+2016
to
+2020
|
||
| // Validate the htpasswd format | ||
| if err := validateHtpasswdFormat(usersSecretBytes); err != nil { | ||
| return nil, err | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -719,6 +719,11 @@ func Test_validateHtpasswdFormat(t *testing.T) { | |
| htpasswd: "user1:{SHA}W6ph5Mm5Pz8GgiULbPgzG37mj9g=\nuser2:$apr1$hashed_user2_password", | ||
| wantError: true, | ||
| }, | ||
| { | ||
| name: "valid htpasswd with CRLF line endings (Windows-style)", | ||
| htpasswd: "user1:{SHA}W6ph5Mm5Pz8GgiULbPgzG37mj9g=\r\nuser2:{SHA}qUqP5cyxm6YcTAhz05Hph5gvu9M=\r\n", | ||
| wantError: false, | ||
| }, | ||
|
Comment on lines
+722
to
+726
|
||
| } | ||
|
|
||
| for _, tt := range tests { | ||
|
|
||
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.
This normalization only replaces CRLF (
\r\n). If the secret contains stray\rcharacters (e.g., mixed line endings or a final line ending with\ronly), they will still be passed through to Envoy and can trigger the same rejection. Consider also stripping standalone\r(e.g., replace all\rwith empty) or normalizing more generally.