Some checks failed
Use-case regression gate / usecase-regressions (push) Failing after 7m34s
Assistant: codex Assistant-Model: gpt-6.1-sol Assistant-Session: 01a198e4-7903-75b3-aaf3-c89ddac9437d
80 lines
2.6 KiB
Python
Executable file
80 lines
2.6 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
"""Open only the OpenBao administrator's KeyCape request in Windows Edge InPrivate."""
|
|
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
from urllib.parse import parse_qs, urlencode, urlsplit, urlunsplit
|
|
|
|
EDGE = Path("/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe")
|
|
POWERSHELL = "/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe"
|
|
|
|
|
|
def fresh_url(value):
|
|
url = urlsplit(value)
|
|
query = parse_qs(url.query, keep_blank_values=True)
|
|
if (
|
|
url.scheme != "https"
|
|
or url.hostname != "kc.coulomb.social"
|
|
or url.port not in (None, 443)
|
|
or url.username
|
|
or url.password
|
|
or url.fragment
|
|
or url.path != "/authorize"
|
|
or any(c in value for c in "\r\n\x00")
|
|
or query.get("client_id") != ["openbao-admin"]
|
|
or query.get("redirect_uri")
|
|
not in (["http://localhost:8250/oidc/callback"], ["http://127.0.0.1:8250/oidc/callback"])
|
|
):
|
|
raise ValueError("unreviewed_browser_request")
|
|
query["prompt"] = ["login"]
|
|
query["max_age"] = ["0"]
|
|
return urlunsplit((url.scheme, url.netloc, url.path, urlencode(query, doseq=True), ""))
|
|
|
|
|
|
def windows_profile(path):
|
|
converted = subprocess.run(
|
|
["wslpath", "-w", path],
|
|
check=True,
|
|
capture_output=True,
|
|
text=True,
|
|
timeout=5,
|
|
)
|
|
windows = converted.stdout.strip()
|
|
if not windows or any(c in windows for c in "\r\n\x00"):
|
|
raise ValueError("unreviewed_browser_profile")
|
|
return windows
|
|
|
|
|
|
def main():
|
|
profile = os.environ.get("SMTP_EDGE_PROFILE")
|
|
if len(sys.argv) != 2 or not EDGE.is_file() or not profile:
|
|
return 1
|
|
try:
|
|
url = fresh_url(sys.argv[1])
|
|
result = subprocess.run(
|
|
[
|
|
POWERSHELL,
|
|
"-NoProfile",
|
|
"-NonInteractive",
|
|
"-Command",
|
|
'$ErrorActionPreference="Stop"; $profile=[Console]::In.ReadLine(); '
|
|
"$u=[Console]::In.ReadLine(); "
|
|
"Start-Process -FilePath "
|
|
'"C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe" '
|
|
'-ArgumentList @("--inprivate","--user-data-dir="+$profile,$u)',
|
|
],
|
|
input=(windows_profile(profile) + "\n" + url + "\n").encode(),
|
|
stdout=subprocess.DEVNULL,
|
|
stderr=subprocess.DEVNULL,
|
|
timeout=20,
|
|
check=False,
|
|
)
|
|
return int(result.returncode != 0)
|
|
except Exception:
|
|
return 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|