mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-09-21 18:50:13 +00:00
fix(agentcompat): classify Windows absolute paths
Co-authored-by: naiba/CloudCode <hi+cloudcode@nai.ba>
This commit is contained in:
@@ -90,6 +90,9 @@ func validateRelativeAgentPath(candidate string, destructive bool) (string, erro
|
|||||||
if strings.TrimSpace(candidate) == "" {
|
if strings.TrimSpace(candidate) == "" {
|
||||||
return "", rejectPath(PathRejectionEmpty)
|
return "", rejectPath(PathRejectionEmpty)
|
||||||
}
|
}
|
||||||
|
if hasWindowsAbsolutePath(candidate) {
|
||||||
|
return "", rejectPath(PathRejectionAbsolute)
|
||||||
|
}
|
||||||
if hasWindowsVolume(candidate) {
|
if hasWindowsVolume(candidate) {
|
||||||
return "", rejectPath(PathRejectionVolume)
|
return "", rejectPath(PathRejectionVolume)
|
||||||
}
|
}
|
||||||
@@ -118,6 +121,10 @@ func validateRelativeAgentPath(candidate string, destructive bool) (string, erro
|
|||||||
return nativeRelative, nil
|
return nativeRelative, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hasWindowsAbsolutePath(candidate string) bool {
|
||||||
|
return len(candidate) >= 3 && ((candidate[0] >= 'A' && candidate[0] <= 'Z') || (candidate[0] >= 'a' && candidate[0] <= 'z')) && candidate[1] == ':' && (candidate[2] == '\\' || candidate[2] == '/')
|
||||||
|
}
|
||||||
|
|
||||||
func hasWindowsVolume(candidate string) bool {
|
func hasWindowsVolume(candidate string) bool {
|
||||||
if strings.HasPrefix(candidate, `\\`) || strings.HasPrefix(candidate, `//`) {
|
if strings.HasPrefix(candidate, `\\`) || strings.HasPrefix(candidate, `//`) {
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -52,16 +52,17 @@ func TestFixture_AgentPathRejectsParentEscape(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFixture_AgentPathRejectsVolumeOrSeparatorEscape(t *testing.T) {
|
func TestFixture_AgentPathRejectsWindowsVolumeOrSeparatorEscape(t *testing.T) {
|
||||||
root := newTestAgentRoot(t, "agent-volume")
|
root := newTestAgentRoot(t, "agent-volume")
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
candidate string
|
candidate string
|
||||||
reason PathRejectionReason
|
reason PathRejectionReason
|
||||||
}{
|
}{
|
||||||
{name: "drive absolute", candidate: `C:\outside.txt`, reason: PathRejectionVolume},
|
{name: "drive absolute", candidate: `C:\outside.txt`, reason: PathRejectionAbsolute},
|
||||||
{name: "drive relative", candidate: `C:outside.txt`, reason: PathRejectionVolume},
|
{name: "drive relative", candidate: `C:outside.txt`, reason: PathRejectionVolume},
|
||||||
{name: "UNC", candidate: `\\server\share\outside.txt`, reason: PathRejectionVolume},
|
{name: "UNC", candidate: `\\server\share\outside.txt`, reason: PathRejectionVolume},
|
||||||
|
{name: "extended UNC", candidate: `\\?\UNC\server\share\outside.txt`, reason: PathRejectionVolume},
|
||||||
{name: "alternate separator", candidate: `inside\outside.txt`, reason: PathRejectionSeparator},
|
{name: "alternate separator", candidate: `inside\outside.txt`, reason: PathRejectionSeparator},
|
||||||
{name: "empty component", candidate: "inside//outside.txt", reason: PathRejectionSeparator},
|
{name: "empty component", candidate: "inside//outside.txt", reason: PathRejectionSeparator},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ func TestLegacyFM_RejectedPathDispatchesNoFrame(t *testing.T) {
|
|||||||
{name: "absolute", candidate: filepath.Join(t.TempDir(), "outside"), wantReason: fixture.PathRejectionAbsolute},
|
{name: "absolute", candidate: filepath.Join(t.TempDir(), "outside"), wantReason: fixture.PathRejectionAbsolute},
|
||||||
{name: "parent", candidate: "../outside", wantReason: fixture.PathRejectionParent},
|
{name: "parent", candidate: "../outside", wantReason: fixture.PathRejectionParent},
|
||||||
{name: "destructive root", candidate: ".", wantReason: fixture.PathRejectionDestructiveRoot},
|
{name: "destructive root", candidate: ".", wantReason: fixture.PathRejectionDestructiveRoot},
|
||||||
{name: "volume", candidate: `C:\outside`, wantReason: fixture.PathRejectionVolume},
|
{name: "absolute", candidate: `C:\outside`, wantReason: fixture.PathRejectionAbsolute},
|
||||||
{name: "separator", candidate: `inside\outside`, wantReason: fixture.PathRejectionSeparator},
|
{name: "separator", candidate: `inside\outside`, wantReason: fixture.PathRejectionSeparator},
|
||||||
{name: "symlink parent", candidate: "linked/file", wantReason: fixture.PathRejectionSymlinkParent},
|
{name: "symlink parent", candidate: "linked/file", wantReason: fixture.PathRejectionSymlinkParent},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user