@@ -207,6 +207,60 @@ func TestNewEmptyLoader(t *testing.T) {
207207 require .Error (t , err )
208208}
209209
210+ func TestLoaderRejectsMalformedPath (t * testing.T ) {
211+ // A YAML indentation error can collapse two resource entries into one:
212+ // resources:
213+ // - ../../base
214+ // - ../../shared/prod
215+ // becomes the single string: "../../base - ../../shared/prod"
216+ //
217+ // filepath.Clean normalizes this to "../../shared/prod", silently
218+ // dropping the "../../base" reference. The loader must reject paths
219+ // with inner ".." components that cause this silent absorption.
220+ // See https://github.com/kubernetes-sigs/kustomize/issues/5979
221+ fSys := filesys .MakeFsInMemory ()
222+ require .NoError (t , fSys .MkdirAll ("/base" ))
223+ require .NoError (t , fSys .MkdirAll ("/shared/prod" ))
224+ require .NoError (t , fSys .MkdirAll ("/overlays/prod1" ))
225+
226+ l1 := NewLoaderOrDie (RestrictionNone , fSys , "/overlays/prod1" )
227+
228+ // The exact bug from issue #5979.
229+ _ , err := l1 .New ("../../base - ../../shared/prod" )
230+ require .Error (t , err )
231+ require .Contains (t , err .Error (), "ambiguous" )
232+
233+ // Same structural problem without the YAML artifact.
234+ _ , err = l1 .New ("a/b/../../other" )
235+ require .Error (t , err )
236+ require .Contains (t , err .Error (), "ambiguous" )
237+ }
238+
239+ func TestHasInnerDotDot (t * testing.T ) {
240+ cases := map [string ]bool {
241+ // Safe: leading ".." only
242+ "../base" : false ,
243+ "../../shared/prod" : false ,
244+ ".." : false ,
245+ // Safe: no ".." at all
246+ "foo/bar" : false ,
247+ "foo/bar/" : false ,
248+ "foo//bar" : false ,
249+ "./foo/bar" : false ,
250+ "https://root" : false ,
251+ // Dangerous: inner ".." absorbs preceding components
252+ "../../base - ../../shared/prod" : true ,
253+ "a/b/../../c" : true ,
254+ "foo/../bar" : true ,
255+ "a/.." : true ,
256+ }
257+ for path , want := range cases {
258+ t .Run (path , func (t * testing.T ) {
259+ require .Equal (t , want , hasInnerDotDot (path ), "hasInnerDotDot(%q)" , path )
260+ })
261+ }
262+ }
263+
210264func TestNewRemoteLoaderDoesNotExist (t * testing.T ) {
211265 _ , err := makeLoader ().New ("https://example.com/org/repo" )
212266 require .ErrorContains (t , err , "fetch" )
0 commit comments