Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add File.target validation and escaping #222

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions lib/files.ncl
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
let nix = import "./nix-interop/nix.ncl" in
let RelativePath =
std.contract.from_predicate (fun x => !(x |> std.string.characters |> std.array.at 0 == "/"))
Chan-Siu-Man marked this conversation as resolved.
Show resolved Hide resolved
in
let NoTraversal =
std.contract.from_predicate
(
fun x => !(x |> std.string.split "/" |> std.array.any (fun part => part == ".."))
Chan-Siu-Man marked this conversation as resolved.
Show resolved Hide resolved
)
in
let File = {
target
| doc m%"
The file to write to.
If null, defaults to the attribute name of the file.
"%
| String
| std.string.NonEmpty # avoids ""
| RelativePath # avoids "/etc/passwd"
| NoTraversal # avoids "../../../../../../../etc/passwd"
| optional,
content
| doc m%"
Expand Down Expand Up @@ -72,7 +83,12 @@ let regenerate_files | Files -> nix.derivation.Derivation
}
file_descr.materialisation_method
in
nix-s%"regenerate_function "%{copy_command}" "%{file_descr.file}" "%{file_descr.target}""%
let shell_escape = fun path =>
path
|> std.string.replace "\\" "\\\\"
|> std.string.replace m%"""% m%"\""%
in
nix-s%"regenerate_function "%{copy_command}" "%{file_descr.file}" "%{shell_escape file_descr.target}""%
Chan-Siu-Man marked this conversation as resolved.
Show resolved Hide resolved
in
let regenerate_files = nix-s%"
%{regenerate_function}
Expand Down
Loading