flawopen.com/Teardowns/CVE-2024-32002
사내 배달원이 '101호'로 중요 서류를 배달하는 상황을 상상해 보십시오. 공격자가 101호 문에 '101호는 임원 전용 금고실로 이전했습니다'라는 가짜 팻말을 붙였습니다. 배달원은 의심 없이 화살표를 따라 금고실 안에 서류를 넣었습니다. Git에서 배달원은 서브모듈 클론 프로세스였고, 가짜 팻말은 심볼릭 링크였으며, 금고실은 스크립트가 자동 실행되는 숨김 폴더 .git/hooks/ 였습니다.
git clone --recursive <url>builtin/submodule--helper.c 및 dir.c에서 Git은 서브모듈 클론 경로의 상위 디렉터리가 작업 트리 외부를 가리키는 심볼릭 링크인지 검증하지 않았습니다.
// Git clone created submodule directory blindly
static int clone_submodule(const struct module_clone_data *clone_data)
{
struct strbuf sb = STRBUF_INIT;
// BUG: clone_data->path could traverse an existing symlink
strbuf_addf(&sb, "%s", clone_data->path);
safe_create_leading_directories(sb.buf);
return do_clone(clone_data);
}
// Fixed: Refuse to clone into or through symlinked path components
static int clone_submodule(const struct module_clone_data *clone_data)
{
struct strbuf sb = STRBUF_INIT;
// FIX: Validate that no parent component is a symlink
if (path_has_symlinks(clone_data->path))
die(_("fatal: submodule path '%s' contains a symlink"),
clone_data->path);
strbuf_addf(&sb, "%s", clone_data->path);
return do_clone(clone_data);
}
.git/modules/sub를 가리키는 sub라는 심볼릭 링크를 저장소에 포함합니다.SUB/hooks 서브모듈 쓰기 작업이 심볼릭 링크를 타고 내부 훅 디렉터리로 유도됩니다.post-checkout 훅 스크립트가 기록되고, git clone 완료 시점에 사용자의 권한으로 즉시 실행됩니다.Path/A와 path/a는 동일한 위치를 참조합니다..git/ 폴더를 보호했습니다.