* provider: a sign-in on Windows installs its CLI past Microsoft Defender, which stopped the installer's command line as a Trojan (#1225) On Windows the sign-in ran the vendor's installer as `powershell -NoProfile -ExecutionPolicy Bypass -Command irm https://static.devin.ai/cli/setup.ps1 | iex`, and Microsoft Defender takes that command line for Trojan:Win32/Commando.A!ml. It stopped PowerShell before it ran, so Devin's sign-in failed with "installing Devin CLI failed (fork/exec C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe: Access is denied.)" while Windows Security said it found a threat (hisiling, Windows 11, v0.1.1106, three tries, three detections). The one-liner now reaches `powershell -NoProfile -ExecutionPolicy Bypass -Command -` on stdin, as one typed into PowerShell does, so no command line carries it. Cursor's and Grok's installers go the same way. The installer's output and exit code come back as before, and one that would ask something still reads nothing. TestWindowsInstallerNotOnCommandLine fails without the change on Windows 11 (PowerShell's command line carries the installer: powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Output ([Environment]::CommandLine); exit 7") and passes with it. On the same machine, with Defender's real-time protection on, Devin's sign-in started the way the window's button starts it (provider.StartSignIn, from a program with no console) ran the real setup.ps1 with no detection and installed Devin CLI 3000.11.3. go vet ./internal/provider and go test -run 'Install|SignIn' ./internal/provider pass on Windows; go vet -tags nogui ./..., go build -tags nogui ./..., GOOS=windows go build ./... and the windowsgui build pass on Linux. * provider: Devin's sign-in on Windows goes on once the Devin CLI is in place, where its installer's `devin setup` held it for ten minutes and was left running (#1225) Devin's setup.ps1 ends in `devin setup`, whose menu asking how to sign in waits for a key on the console. The console an installer gets from magpie has no window (the app has none, so its children get CREATE_NO_WINDOW) and magpie keeps its output, so no one can answer it: the sign-in stayed "installing" until installTimeout ended the installer ten minutes later, and `devin setup` went on running. It waits the same way with stdin from NUL, and CI=true or TERM=dumb don't change it; `devin setup` has no option but --force-manual-token-flow. On Windows, the installer of a CLI marked setup (Devin's) now runs as a proc.Tree. Once the CLI is in place, read with the user PATH the installer wrote, it has installerTail (5s) to end by itself, then it is ended with everything it started, as it is when the sign-in is canceled or times out. magpie's own sign-in follows as before. Cursor's and Grok's installers, and every installer off Windows, run as they did. TestWindowsDevinSetupDoesNotHoldTheSignIn fails without the change on Windows 11 (the sign-in waited 47s for the installer after the CLI was in place, installTimeout set to 45s) and passes with it in 6s, its setup ended. On the same machine the real Devin sign-in went from installing to Devin's sign-in page in 18s, with no devin.exe or PowerShell left running and setup.ps1's distribution marker and user PATH written; with the first change alone it took ten minutes and left `devin.exe setup` running. go vet ./internal/provider and go test -run 'Install|SignIn|NotOnCommandLine|DevinSetup' ./internal/provider pass on Windows; GOOS=windows go vet ./internal/provider ./internal/proc passes on Linux. --------- Co-authored-by: Siling <179151647+hisiling@users.noreply.github.com>
95 lines
2.7 KiB
Go
95 lines
2.7 KiB
Go
package provider
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strconv"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"golang.org/x/sys/windows"
|
|
)
|
|
|
|
// Devin's installer ends in `devin setup`, whose menu asking how to sign in
|
|
// waits for a key on a console no one can answer: the sign-in went on only
|
|
// after installTimeout, with `devin setup` left running. Once the CLI is in
|
|
// place the installer is ended a moment later, with what it started.
|
|
func TestWindowsDevinSetupDoesNotHoldTheSignIn(t *testing.T) {
|
|
dir := t.TempDir()
|
|
exe := filepath.Join(dir, "devin.exe")
|
|
pidFile := filepath.Join(dir, "setup.pid")
|
|
oldExe := DevinExecutable
|
|
DevinExecutable = func() string {
|
|
if isFile(exe) {
|
|
return exe
|
|
}
|
|
return ""
|
|
}
|
|
t.Cleanup(func() { DevinExecutable = oldExe })
|
|
oldTimeout := installTimeout
|
|
installTimeout = 45 * time.Second
|
|
t.Cleanup(func() { installTimeout = oldTimeout })
|
|
c, _ := cliFor("devin")
|
|
// as Devin's: the CLI goes in place, then a setup runs that waits
|
|
c.ps = fmt.Sprintf("Set-Content -LiteralPath '%s' -Value devin; "+
|
|
"$p = Start-Process -FilePath ping.exe -ArgumentList '-n','600','127.0.0.1' -NoNewWindow -PassThru; "+
|
|
"Set-Content -LiteralPath '%s' -Value $p.Id; $p.WaitForExit()", exe, pidFile)
|
|
start := time.Now()
|
|
err := installCLI(context.Background(), c)
|
|
took := time.Since(start)
|
|
pid := 0
|
|
if b, rerr := os.ReadFile(pidFile); rerr == nil {
|
|
pid, _ = strconv.Atoi(strings.TrimSpace(string(b)))
|
|
}
|
|
t.Cleanup(func() { endPing(pid) })
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if pid == 0 {
|
|
t.Fatal("the installer's setup never ran")
|
|
}
|
|
if took > 30*time.Second {
|
|
t.Fatalf("the sign-in waited %s for the installer after the CLI was in place", took.Round(time.Second))
|
|
}
|
|
if pingRunning(pid) {
|
|
t.Fatalf("the installer's setup (pid %d) is left running", pid)
|
|
}
|
|
}
|
|
|
|
// pingRunning is whether pid is a ping.exe that is still running: a pid
|
|
// let go of can be another program's soon after.
|
|
func pingRunning(pid int) bool {
|
|
if pid == 0 {
|
|
return false
|
|
}
|
|
h, err := windows.OpenProcess(windows.PROCESS_QUERY_LIMITED_INFORMATION, false, uint32(pid))
|
|
if err != nil {
|
|
return false
|
|
}
|
|
defer windows.CloseHandle(h)
|
|
var code uint32
|
|
if windows.GetExitCodeProcess(h, &code) != nil || code != 259 { // STILL_ACTIVE
|
|
return false
|
|
}
|
|
buf := make([]uint16, windows.MAX_PATH)
|
|
n := uint32(len(buf))
|
|
if windows.QueryFullProcessImageName(h, 0, &buf[0], &n) != nil {
|
|
return false
|
|
}
|
|
return strings.EqualFold(filepath.Base(windows.UTF16ToString(buf[:n])), "ping.exe")
|
|
}
|
|
|
|
// endPing ends the setup a test started, where it was left running.
|
|
func endPing(pid int) {
|
|
if !pingRunning(pid) {
|
|
return
|
|
}
|
|
if h, err := windows.OpenProcess(windows.PROCESS_TERMINATE, false, uint32(pid)); err == nil {
|
|
_ = windows.TerminateProcess(h, 1)
|
|
windows.CloseHandle(h)
|
|
}
|
|
}
|