1+ // spell-checker: ignore evilalpha, evilgamma
12import { getTarget } from '../../src/router' ;
23
34describe ( 'router unit test' , ( ) => {
@@ -106,6 +107,12 @@ describe('router unit test', () => {
106107 result = getTarget ( fakeReq , proxyOptionWithRouter ) ;
107108 return expect ( result ) . resolves . toBe ( 'http://localhost:6002' ) ;
108109 } ) ;
110+
111+ it ( 'should not match host-only config when host contains key as substring' , ( ) => {
112+ fakeReq . headers . host = 'evilalpha.localhost' ;
113+ result = getTarget ( fakeReq , proxyOptionWithRouter ) ;
114+ return expect ( result ) . resolves . toBeUndefined ( ) ;
115+ } ) ;
109116 } ) ;
110117
111118 describe ( 'with host and host + path config' , ( ) => {
@@ -128,6 +135,20 @@ describe('router unit test', () => {
128135 result = getTarget ( fakeReq , proxyOptionWithRouter ) ;
129136 return expect ( result ) . resolves . toBe ( 'http://localhost:6003' ) ;
130137 } ) ;
138+
139+ it ( 'should not match host+path config when host is a superstring' , ( ) => {
140+ fakeReq . headers . host = 'evilgamma.localhost' ;
141+ fakeReq . url = '/api' ;
142+ result = getTarget ( fakeReq , proxyOptionWithRouter ) ;
143+ return expect ( result ) . resolves . toBeUndefined ( ) ;
144+ } ) ;
145+
146+ it ( 'should not match host+path config when host only contains host as a substring' , ( ) => {
147+ fakeReq . headers . host = 'gamma.localhost.evil' ;
148+ fakeReq . url = '/api/books/123' ;
149+ result = getTarget ( fakeReq , proxyOptionWithRouter ) ;
150+ return expect ( result ) . resolves . toBeUndefined ( ) ;
151+ } ) ;
131152 } ) ;
132153
133154 describe ( 'with just the path' , ( ) => {
@@ -148,6 +169,12 @@ describe('router unit test', () => {
148169 result = getTarget ( fakeReq , proxyOptionWithRouter ) ;
149170 return expect ( result ) . resolves . toBeUndefined ( ) ;
150171 } ) ;
172+
173+ it ( 'should not match path config when key appears as non-prefix substring' , ( ) => {
174+ fakeReq . url = '/prefix/rest' ;
175+ result = getTarget ( fakeReq , proxyOptionWithRouter ) ;
176+ return expect ( result ) . resolves . toBeUndefined ( ) ;
177+ } ) ;
151178 } ) ;
152179
153180 describe ( 'matching order of router config' , ( ) => {
0 commit comments