-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cue/interpreter/embed: don't allow hidden files in glob
This could later be allowed as an option. This is a security feature. We also disallow hidden files on Windows for the same reason, which is a bit more involved. Note that this results in potentially slightly different behavior under Windows and Unix. This is already the case. For instance, the set of valid filenames is different on the different supported OSes. So we accept this discrepancy in favor of added security. Verified that without adding the new logic, the hidden file that was added to embed.txtar gets included in the output. Issue #2031 Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: Iacff803f4c388d1f2792665ed5adb32f68f00ffa Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1196775 TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Roger Peppe <[email protected]> Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Daniel Martí <[email protected]>
- Loading branch information
Showing
3 changed files
with
66 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2024 CUE Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package embed | ||
|
||
import "testing" | ||
|
||
func TestIsHidden(t *testing.T) { | ||
// These test cases are the same for both Unix and Windows. | ||
testCases := []struct { | ||
path string | ||
want bool | ||
}{{ | ||
path: "", | ||
want: false, | ||
}, { | ||
path: "foo", | ||
want: false, | ||
}, { | ||
path: ".foo", | ||
want: true, | ||
}, { | ||
path: "foo/bar", | ||
want: false, | ||
}, { | ||
path: "foo/.bar", | ||
want: true, | ||
}, { | ||
path: ".foo/bar", | ||
want: true, | ||
}, { | ||
path: "x/.foo/bar", | ||
want: true, | ||
}} | ||
c := &compiler{dir: "/tmp"} | ||
for _, tc := range testCases { | ||
t.Run(tc.path, func(t *testing.T) { | ||
got := c.isHidden(tc.path) | ||
if got != tc.want { | ||
t.Errorf("isHidden(%q) = %t; want %t", tc.path, got, tc.want) | ||
} | ||
}) | ||
} | ||
} |