File tree Expand file tree Collapse file tree 3 files changed +52
-0
lines changed Expand file tree Collapse file tree 3 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -166,4 +166,5 @@ var (
166
166
167
167
ErrLetsEncryptMissingCacheDir = errors .New ("letsencrypt cache dir has not been set" )
168
168
ErrHijackerMethodMissing = errors .New ("writer does not implement http.Hijacker method" )
169
+ ErrInvalidOriginWithCreds = errors .New ("origin cannot be set to * together with AllowedCredentials true" )
169
170
)
Original file line number Diff line number Diff line change @@ -328,6 +328,7 @@ func (r *Config) IsValid() error {
328
328
r .isOpenIDProviderProxyValid ,
329
329
r .isMaxIdlleConnValid ,
330
330
r .isSameSiteValid ,
331
+ r .isCorsValid ,
331
332
r .isTLSFilesValid ,
332
333
r .isAdminTLSFilesValid ,
333
334
r .isLetsEncryptValid ,
@@ -910,3 +911,12 @@ func (r *Config) isEnableLoAValid() error {
910
911
}
911
912
return nil
912
913
}
914
+
915
+ func (r * Config ) isCorsValid () error {
916
+ for _ , origin := range r .CorsOrigins {
917
+ if origin == "*" && r .CorsCredentials {
918
+ return apperrors .ErrInvalidOriginWithCreds
919
+ }
920
+ }
921
+ return nil
922
+ }
Original file line number Diff line number Diff line change @@ -2592,3 +2592,44 @@ func TestEnableLoa(t *testing.T) {
2592
2592
)
2593
2593
}
2594
2594
}
2595
+
2596
+ func TestIsCorsValid (t * testing.T ) {
2597
+ testCases := []struct {
2598
+ Name string
2599
+ Config * Config
2600
+ Valid bool
2601
+ }{
2602
+ {
2603
+ Name : "ValidOrigin" ,
2604
+ Config : & Config {
2605
+ CorsOrigins : []string {"example.com" },
2606
+ CorsCredentials : false ,
2607
+ },
2608
+ Valid : true ,
2609
+ },
2610
+ {
2611
+ Name : "InvalidOrigin" ,
2612
+ Config : & Config {
2613
+ CorsOrigins : []string {"*" },
2614
+ CorsCredentials : true ,
2615
+ },
2616
+ Valid : false ,
2617
+ },
2618
+ }
2619
+
2620
+ for _ , testCase := range testCases {
2621
+ t .Run (
2622
+ testCase .Name ,
2623
+ func (t * testing.T ) {
2624
+ err := testCase .Config .isCorsValid ()
2625
+ if err != nil && testCase .Valid {
2626
+ t .Fatalf ("Expected test not to fail" )
2627
+ }
2628
+
2629
+ if err == nil && ! testCase .Valid {
2630
+ t .Fatalf ("Expected test to fail" )
2631
+ }
2632
+ },
2633
+ )
2634
+ }
2635
+ }
You can’t perform that action at this time.
0 commit comments