File tree Expand file tree Collapse file tree
test/configCases/asset-modules/http-url Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ " webpack " : patch
3+ ---
4+
5+ Fixed a user information bypass vulnerability in the HttpUriPlugin plugin.
Original file line number Diff line number Diff line change @@ -953,12 +953,28 @@ class HttpUriPlugin {
953953 * @returns {boolean } true when allowed, otherwise false
954954 */
955955 const isAllowed = ( uri ) => {
956+ let parsedUri ;
957+ try {
958+ // Parse the URI to prevent userinfo bypass attacks
959+ // (e.g., http://allowed@malicious/path where @malicious is the actual host)
960+ parsedUri = new URL ( uri ) ;
961+ } catch ( _err ) {
962+ return false ;
963+ }
956964 for ( const allowed of allowedUris ) {
957965 if ( typeof allowed === "string" ) {
958- if ( uri . startsWith ( allowed ) ) return true ;
966+ let parsedAllowed ;
967+ try {
968+ parsedAllowed = new URL ( allowed ) ;
969+ } catch ( _err ) {
970+ continue ;
971+ }
972+ if ( parsedUri . href . startsWith ( parsedAllowed . href ) ) {
973+ return true ;
974+ }
959975 } else if ( typeof allowed === "function" ) {
960- if ( allowed ( uri ) ) return true ;
961- } else if ( allowed . test ( uri ) ) {
976+ if ( allowed ( parsedUri . href ) ) return true ;
977+ } else if ( allowed . test ( parsedUri . href ) ) {
962978 return true ;
963979 }
964980 }
Original file line number Diff line number Diff line change @@ -16,5 +16,8 @@ module.exports = [
1616 ] ,
1717 [
1818 / h t t p : \/ \/ l o c a l h o s t : 9 9 9 0 \/ r e d i r e c t h a s a n o u t d a t e d l o c k f i l e e n t r y , b u t l o c k f i l e i s f r o z e n /
19+ ] ,
20+ [
21+ / M o d u l e n o t f o u n d : E r r o r : h t t p : \/ \/ l o c a l h o s t : 9 9 9 0 @ 1 2 7 \. 0 \. 0 \. 1 : 9 1 0 0 \/ s e c r e t \. j s d o e s n ' t m a t c h t h e a l l o w e d U r i s p o l i c y /
1922 ]
2023] ;
Original file line number Diff line number Diff line change 1+ "use strict" ;
2+
3+ it ( "should reject URLs with userinfo that bypass allowedUris" , ( ) => {
4+ expect ( ( ) => require ( "http://localhost:9990@127.0.0.1:9100/secret.js" ) ) . toThrow ( ) ;
5+ } ) ;
6+
Original file line number Diff line number Diff line change @@ -102,5 +102,18 @@ module.exports = [
102102 frozen : true
103103 } )
104104 ]
105+ } ,
106+ {
107+ name : "security-userinfo-bypass" ,
108+ ...base ,
109+ entry : "./index.security.js" ,
110+ plugins : [
111+ serverPlugin ,
112+ new HttpUriPlugin ( {
113+ allowedUris,
114+ upgrade : false ,
115+ frozen : false
116+ } )
117+ ]
105118 }
106119] ;
You can’t perform that action at this time.
0 commit comments