@@ -25,6 +25,7 @@ func TestProxyController(t *testing.T) {
2525 log .Init ()
2626
2727 cfg , runtime := test .CreateTestConfigs (t )
28+ cfg .Auth .IP .Block = []string {"198.51.100.9" }
2829
2930 const browserUserAgent = `
3031 Mozilla/5.0 (Linux; Android 8.0.0; SM-G955U Build/R16NW) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Mobile Safari/537.36`
@@ -510,6 +511,94 @@ func TestProxyController(t *testing.T) {
510511 assert .Equal (t , http .StatusUnauthorized , recorder .Code )
511512 },
512513 },
514+ {
515+ description : "App IP block takes precedence over path rules" ,
516+ middlewares : []gin.HandlerFunc {},
517+ run : func (t * testing.T , router * gin.Engine , recorder * httptest.ResponseRecorder ) {
518+ req := httptest .NewRequest ("GET" , "/api/auth/traefik" , nil )
519+ req .Header .Set ("x-forwarded-host" , "acl-precedence-block.example.com" )
520+ req .Header .Set ("x-forwarded-proto" , "https" )
521+ req .Header .Set ("x-forwarded-uri" , "/allowed" )
522+ req .Header .Set ("x-forwarded-for" , "10.10.10.10" )
523+ router .ServeHTTP (recorder , req )
524+
525+ assert .Equal (t , http .StatusForbidden , recorder .Code )
526+ assert .Contains (t , recorder .Header ().Get ("x-tinyauth-location" ), "ip=10.10.10.10" )
527+ },
528+ },
529+ {
530+ description : "App IP allow list takes precedence over path rules" ,
531+ middlewares : []gin.HandlerFunc {},
532+ run : func (t * testing.T , router * gin.Engine , recorder * httptest.ResponseRecorder ) {
533+ req := httptest .NewRequest ("GET" , "/api/auth/traefik" , nil )
534+ req .Header .Set ("x-forwarded-host" , "acl-precedence-allow.example.com" )
535+ req .Header .Set ("x-forwarded-proto" , "https" )
536+ req .Header .Set ("x-forwarded-uri" , "/allowed" )
537+ req .Header .Set ("x-forwarded-for" , "10.10.10.11" )
538+ router .ServeHTTP (recorder , req )
539+
540+ assert .Equal (t , http .StatusForbidden , recorder .Code )
541+ assert .Contains (t , recorder .Header ().Get ("x-tinyauth-location" ), "ip=10.10.10.11" )
542+ },
543+ },
544+ {
545+ description : "Global IP block takes precedence over path rules" ,
546+ middlewares : []gin.HandlerFunc {},
547+ run : func (t * testing.T , router * gin.Engine , recorder * httptest.ResponseRecorder ) {
548+ req := httptest .NewRequest ("GET" , "/api/auth/traefik" , nil )
549+ req .Header .Set ("x-forwarded-host" , "acl-precedence-global.example.com" )
550+ req .Header .Set ("x-forwarded-proto" , "https" )
551+ req .Header .Set ("x-forwarded-uri" , "/allowed" )
552+ req .Header .Set ("x-forwarded-for" , "198.51.100.9" )
553+ router .ServeHTTP (recorder , req )
554+
555+ assert .Equal (t , http .StatusForbidden , recorder .Code )
556+ assert .Contains (t , recorder .Header ().Get ("x-tinyauth-location" ), "ip=198.51.100.9" )
557+ },
558+ },
559+ {
560+ description : "App IP block takes precedence over path block rules" ,
561+ middlewares : []gin.HandlerFunc {},
562+ run : func (t * testing.T , router * gin.Engine , recorder * httptest.ResponseRecorder ) {
563+ req := httptest .NewRequest ("GET" , "/api/auth/traefik" , nil )
564+ req .Header .Set ("x-forwarded-host" , "acl-precedence-path-block.example.com" )
565+ req .Header .Set ("x-forwarded-proto" , "https" )
566+ req .Header .Set ("x-forwarded-uri" , "/public" )
567+ req .Header .Set ("x-forwarded-for" , "10.10.10.10" )
568+ router .ServeHTTP (recorder , req )
569+
570+ assert .Equal (t , http .StatusForbidden , recorder .Code )
571+ assert .Contains (t , recorder .Header ().Get ("x-tinyauth-location" ), "ip=10.10.10.10" )
572+ },
573+ },
574+ {
575+ description : "Path rules allow unrestricted IPs" ,
576+ middlewares : []gin.HandlerFunc {},
577+ run : func (t * testing.T , router * gin.Engine , recorder * httptest.ResponseRecorder ) {
578+ req := httptest .NewRequest ("GET" , "/api/auth/traefik" , nil )
579+ req .Header .Set ("x-forwarded-host" , "acl-precedence-block.example.com" )
580+ req .Header .Set ("x-forwarded-proto" , "https" )
581+ req .Header .Set ("x-forwarded-uri" , "/allowed" )
582+ req .Header .Set ("x-forwarded-for" , "10.10.10.11" )
583+ router .ServeHTTP (recorder , req )
584+
585+ assert .Equal (t , http .StatusOK , recorder .Code )
586+ },
587+ },
588+ {
589+ description : "IP bypass retains highest precedence" ,
590+ middlewares : []gin.HandlerFunc {},
591+ run : func (t * testing.T , router * gin.Engine , recorder * httptest.ResponseRecorder ) {
592+ req := httptest .NewRequest ("GET" , "/api/auth/traefik" , nil )
593+ req .Header .Set ("x-forwarded-host" , "acl-precedence-bypass.example.com" )
594+ req .Header .Set ("x-forwarded-proto" , "https" )
595+ req .Header .Set ("x-forwarded-uri" , "/allowed" )
596+ req .Header .Set ("x-forwarded-for" , "10.10.10.10" )
597+ router .ServeHTTP (recorder , req )
598+
599+ assert .Equal (t , http .StatusOK , recorder .Code )
600+ },
601+ },
513602 {
514603 description : "Ensure ip bypass ACL works on forward auth" ,
515604 middlewares : []gin.HandlerFunc {},
0 commit comments