@@ -83,16 +83,21 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
83
83
asset = typeof asset === 'string' ? { glob : asset } : asset ;
84
84
// Add defaults.
85
85
// Input is always resolved relative to the appRoot.
86
- asset . input = path . resolve ( appRoot , asset . input || '' ) ;
86
+ asset . input = path . resolve ( appRoot , asset . input || '' ) . replace ( / \\ / g , '/' ) ;
87
87
asset . output = asset . output || '' ;
88
88
asset . glob = asset . glob || '' ;
89
89
90
90
// Prevent asset configurations from writing outside of the output path, except if the user
91
91
// specify a configuration flag.
92
92
// Also prevent writing outside the project path. That is not overridable.
93
- const fullOutputPath = path . resolve ( buildOptions . outputPath , asset . output ) ;
94
- if ( ! fullOutputPath . startsWith ( path . resolve ( buildOptions . outputPath ) ) ) {
95
- if ( ! fullOutputPath . startsWith ( projectRoot ) ) {
93
+ const absoluteOutputPath = path . resolve ( buildOptions . outputPath ) ;
94
+ const absoluteAssetOutput = path . resolve ( absoluteOutputPath , asset . output ) ;
95
+ const outputRelativeOutput = path . relative ( absoluteOutputPath , absoluteAssetOutput ) ;
96
+
97
+ if ( outputRelativeOutput . startsWith ( '..' ) || path . isAbsolute ( outputRelativeOutput ) ) {
98
+
99
+ const projectRelativeOutput = path . relative ( projectRoot , absoluteAssetOutput ) ;
100
+ if ( projectRelativeOutput . startsWith ( '..' ) || path . isAbsolute ( projectRelativeOutput ) ) {
96
101
const message = 'An asset cannot be written to a location outside the project.' ;
97
102
throw new SilentError ( message ) ;
98
103
}
@@ -106,7 +111,8 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
106
111
}
107
112
108
113
// Prevent asset configurations from reading files outside of the project.
109
- if ( ! asset . input . startsWith ( projectRoot ) ) {
114
+ const projectRelativeInput = path . relative ( projectRoot , asset . input ) ;
115
+ if ( projectRelativeInput . startsWith ( '..' ) || path . isAbsolute ( projectRelativeInput ) ) {
110
116
const message = 'An asset cannot be read from a location outside the project.' ;
111
117
throw new SilentError ( message ) ;
112
118
}
0 commit comments