@@ -129,6 +129,54 @@ func TestBasicAuthWithFakepassword(t *testing.T) {
129
129
login ()
130
130
}
131
131
132
+ // TestByPassBasicAuthVuln tests for CVE-2022-46146.
133
+ func TestByPassBasicAuthVuln (t * testing.T ) {
134
+ server := & http.Server {
135
+ Handler : http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
136
+ w .Write ([]byte ("Hello World!" ))
137
+ }),
138
+ }
139
+
140
+ done := make (chan struct {})
141
+ t .Cleanup (func () {
142
+ if err := server .Shutdown (context .Background ()); err != nil {
143
+ t .Fatal (err )
144
+ }
145
+ <- done
146
+ })
147
+
148
+ go func () {
149
+ flags := FlagConfig {
150
+ WebListenAddresses : & ([]string {port }),
151
+ WebSystemdSocket : OfBool (false ),
152
+ WebConfigFile : OfString ("testdata/web_config_users_noTLS.good.yml" ),
153
+ }
154
+ ListenAndServe (server , & flags , testlogger )
155
+ close (done )
156
+ }()
157
+
158
+ login := func (username , password string ) {
159
+ client := & http.Client {}
160
+ req , err := http .NewRequest ("GET" , "http://localhost" + port , nil )
161
+ if err != nil {
162
+ t .Fatal (err )
163
+ }
164
+ req .SetBasicAuth (username , password )
165
+ r , err := client .Do (req )
166
+ if err != nil {
167
+ t .Fatal (err )
168
+ }
169
+ if r .StatusCode != 401 {
170
+ t .Fatalf ("bad return code, expected %d, got %d" , 401 , r .StatusCode )
171
+ }
172
+ }
173
+
174
+ // Poison the cache.
175
+ login ("alice$2y$12$1DpfPeqF9HzHJt.EWswy1exHluGfbhnn3yXhR7Xes6m3WJqFg0Wby" , "fakepassword" )
176
+ // Login with a wrong password.
177
+ login ("alice" , "$2y$10$QOauhQNbBCuQDKes6eFzPeMqBSjb7Mr5DUmpZ/VcEd00UAV/LDeSifakepassword" )
178
+ }
179
+
132
180
// TestHTTPHeaders validates that HTTP headers are added correctly.
133
181
func TestHTTPHeaders (t * testing.T ) {
134
182
server := & http.Server {
0 commit comments