fix(lambda): normalize backslash ZIP path separators on extraction (#1215)

* fix(lambda): normalize backslash ZIP path separators on extraction

PowerShell's Compress-Archive writes ZIP entry names with '\' separators,
violating the ZIP spec (APPNOTE.TXT 4.4.17 mandates '/'). On Linux '\' is a
literal filename character, so a .NET/Blazor publish archive extracted to a
single flat file named "wwwroot\app.css" instead of nested directories,
breaking static-file lookups under /var/task.

Normalize '\' -> '/' before any path handling so such archives extract to the
correct nested paths, matching how real AWS Lambda unpacks them. A trailing
separator is also treated as a directory entry, since the backslash form would
otherwise slip past ZipEntry.isDirectory(). The path-traversal guard now runs
on the normalized name, so "..\..\evil" is still rejected.

Closes #1198

* fix(lambda): warn on backslash ZIP separators instead of normalizing

Real AWS Lambda does NOT normalize '\' to '/' in ZIP entry names — a
PowerShell Compress-Archive entry extracts as a literal-named file. The
previous normalization made Floci more forgiving than AWS, letting broken
packages pass locally and fail on deploy.

Replace the normalization with a clear warning that tells the developer
why the backslash entry is problematic and how to repackage correctly
(tar, pwsh, or dotnet lambda CLI). The traversal guard and containment
check stay as-is.
This commit is contained in:
Ben Younes authored and GitHub committed 2026-06-10 21:23:54 -05:00
1 parent 16efcc82eb
commit d96f65afca
2 files changed
+85

No files matched your search

@@ -20,6 +20,8 @@ public class ZipExtractor {
private static final Logger LOG = Logger.getLogger(ZipExtractor.class);
private static final char BACKSLASH = '\\';
public void extractTo(byte[] zipBytes, Path targetDir) throws IOException {
// Resolve to absolute path so that normalize() on entry paths stays comparable
Path absTarget = targetDir.toAbsolutePath().normalize();
@@ -30,6 +32,16 @@ public class ZipExtractor {
while ((entry = zis.getNextEntry()) != null) {
String entryName = entry.getName();
// PowerShell 5 Compress-Archive writes '\' as a literal filename byte on
// Linux. Real AWS Lambda does NOT normalize this (the archive extracts to
// a flat "wwwroot\app.css" file), so neither do we; masking it would let
// a broken package pass locally and then fail on deploy.
if (entryName.indexOf(BACKSLASH) >= 0) {
LOG.warnv("ZIP entry \"{0}\" uses backslash separators (PowerShell Compress-Archive). "
+ "It extracts as a literal filename and will also fail on real AWS Lambda. "
+ "Repackage with tar, PowerShell Core (pwsh), or the dotnet lambda CLI.", entryName);
}
// Security: prevent path traversal
if (entryName.contains("..") || entryName.startsWith("/")) {
LOG.warnv("Skipping suspicious ZIP entry: {0}", entryName);