fix(adb): reject unsafe host file names when pulling one device file (#1962)
pull_adb_file derived its host file name from the last path segment of a caller-supplied device path and joined it to the output directory without checking that the name is usable on the host. A device path ending in a separator, a dot segment, a control character, a Windows reserved device name, a trailing dot or space, or a ':' alternate-data-stream marker could resolve to an unexpected host path or fail opaquely after the transfer. The single-file path now derives the name with POSIX semantics and refuses any non-portable segment as invalid_request before creating a directory or running adb pull. This matches the package path's pending host-name policy and never renames a device-reported file. Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
@@ -478,6 +478,48 @@ exit 1`,
|
||||
});
|
||||
});
|
||||
|
||||
it.each([
|
||||
["/data/local/tmp/..", "dot_segment"],
|
||||
["/data/local/tmp/a\\b", "path_separator"],
|
||||
["/data/local/tmp/CON", "reserved_name"],
|
||||
["/data/local/tmp/report.", "trailing_dot_or_space"],
|
||||
["/data/local/tmp/report:2024", "alternate_data_stream"],
|
||||
] as const)(
|
||||
"refuses the unsafe device path %s before pulling",
|
||||
async (devicePath, reason) => {
|
||||
const { binary, root } = await writeAdbStub(
|
||||
(root) => `if [ "$1" = "version" ]; then ${VERSION_BLOCK}; exit 0; fi
|
||||
: > "${join(root, "pull-ran")}"
|
||||
exit 0`,
|
||||
);
|
||||
const output = join(root, "pulls");
|
||||
const result = await providerOver(binary).execute({
|
||||
operation: "pull_adb_file",
|
||||
input: {
|
||||
serial: "emulator-5554",
|
||||
device_path: devicePath,
|
||||
output_directory: output,
|
||||
},
|
||||
});
|
||||
expect(result.ok).toBe(false);
|
||||
if (result.ok) return;
|
||||
const projected = projectAnalysisError(result.error);
|
||||
expect(projected).toMatchObject({ code: "invalid_request" });
|
||||
expect(projected.details).toMatchObject({
|
||||
issues: [
|
||||
{
|
||||
path: ["device_path"],
|
||||
reason: "invalid_value",
|
||||
message: expect.stringContaining(reason),
|
||||
},
|
||||
],
|
||||
});
|
||||
// No host directory and no adb invocation are effects of a refused pull.
|
||||
await expect(readFile(join(root, "pull-ran"))).rejects.toThrow();
|
||||
await expect(readFile(output)).rejects.toThrow();
|
||||
},
|
||||
);
|
||||
|
||||
it("pushes a file and verifies the device-side digest", async () => {
|
||||
const { binary, root } = await writeAdbStub(
|
||||
() => `if [ "$1" = "version" ]; then ${VERSION_BLOCK}; exit 0; fi
|
||||
|
||||
Reference in New Issue
Block a user