Conversation
This comment has been minimized.
This comment has been minimized.
a294983 to
0eb56cf
Compare
This comment has been minimized.
This comment has been minimized.
0eb56cf to
31b063d
Compare
This comment has been minimized.
This comment has been minimized.
31b063d to
c50e182
Compare
This comment has been minimized.
This comment has been minimized.
|
Thank you for your contribution. unfortunately, one or more of your commits are missing the required "Signed-off-by:" statement. Signing off is part of the Developer Certificate of Origin (DCO) which is used by this project. Read the DCO and project contributing guide carefully, and amend your commits using the git CLI. Note that this does not require any cryptography, keys or special steps to be taken. 💡 Shall we fix this?This will only take a few moments. First, clone your fork and checkout this branch using the git CLI. Next, set up your real name and email address:
Finally, run one of these commands to add the "Signed-off-by" line to your commits. If you only have one commit so far then run: Check that the message has been added properly by running "git log". |
7744b9b to
62555dc
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
62555dc to
28552ae
Compare
This comment has been minimized.
This comment has been minimized.
`handler_folder` from a language template's template.yml was joined onto the build context without a containment check, so a value containing `..` segments could create and copy the function handler tree outside of the build context with the build user's privileges. This allows a malicious or compromised template to write or overwrite arbitrary files on the machine running the build. CreateBuildContext now resolves the handler destination with filesystem-aware path operations and requires it to be a strict descendant of the intended per-function build root. Absolute paths, path traversal and destinations reached through a symbolic link that escapes the build context are rejected, and no directories are created for an out-of-scope destination. Add tests for path traversal, hidden traversal, absolute paths, prefix siblings and symlink escapes. Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
CreateBuildContext removes an existing per-function build directory before recreating it. Joining an unchecked function name allowed a direct SDK caller to use path separators or traversal to move that destructive operation outside BuildDir. Treat BuildDir as the caller-authorized root and require functionName to be one portable filesystem path component before calling RemoveAll. Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
Extra-path validation accepted sibling directories sharing the project's name prefix, allowing reads outside the project. The copy destination also reused the raw input: ../project/shared/sentinel could resolve inside the project but write outside the function's build context. Use filepath.Rel and filepath.IsLocal to check lexical containment and reject the scope root, including differently capitalized Windows paths. Derive each copy destination from the validated relative source path and validate each extra path immediately before copying it. Regression tests cover prefix-sibling rejection, copying to the expected location while preserving an outside sentinel, and scope-root rejection. Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
28552ae to
467d4eb
Compare
AI Pull Request OverviewDisclaimer: This review was generated by automated AI and may contain errors. Do not trust its outputs without human verification. Summary
Approval rating (1-10)9/10. The changes address the scoped path traversal risks with focused validation and relevant regression coverage. Summary per fileSummary per file
Overall AssessmentThe patch is narrowly targeted and improves the build-context containment model in the areas touched by the PR. The move from prefix checks to Detailed ReviewDetailed ReviewNo blocking findings. The changed The The updated The added tests exercise the important edge cases introduced by this patch, including sibling-prefix paths, build-context deletion order, rejected handler overlays, and destination placement for accepted extra paths. AI agent details. |
Description
Validate handler-folder paths to reject absolute paths and traversal outside
the function's build context. Require function names to be single directory
components before clearing the context.
Also fix extra-path validation accepting similarly named sibling directories,
and derive copy destinations from validated relative paths to prevent writes
outside the context.
Motivation and context
handler_folderfrom a language template'stemplate.ymlwas joined onto thebuild context without a containment check, so a value containing
..segmentscould create and copy the function handler tree outside of the build context
with the build user's privileges. This allows a malicious or compromised
template to write or overwrite arbitrary files on the machine running the
build. The existing
pathInScopecheck coveredcopyExtraPaths, but nothandler_folder.How has this been tested
containment and scope-root rejection.
faas-cli build --shrinkwrapagainst a craftedtemplate and verified the build now fails safely with an error and no files
are written outside of the build context.