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