Commit Graph
2 Commits
  • fix(auth): invalidate sessions when 2FA is enabled, fix dev 401 loop
    Add UserService.BumpLoginEpoch and call it from updateSetting when
    TwoFactorEnable flips false → true. Existing cookies (issued under
    the looser no-2FA policy) get a 401 on their next request and are
    forced through the login flow. Disabling 2FA is a relaxation and
    does not bump the epoch — sessions stay valid.
    
    Also fix the dev-mode 401 redirect: targeting `${basePath}login.html`
    breaks when basePath isn't "/" (Vite has no file at e.g.
    "/test/login.html"; the SPA fallback loops the 401). Navigate to
    basePath instead — Vite's bypassMigratedRoute and Go's index
    handler both serve login.html for that path.
    
    Strip stale doc-comment from netsafe and IndexController.logout
    in line with the project's no-inline-comments convention.
  • fix(security): SSRF-guard node and remote HTTP clients
    The Node.Probe and Remote.do paths built outbound URLs by string-
    formatting admin-controlled fields (Scheme/Address/Port/BasePath)
    straight into requests, then dialed the result with the default
    transport. CodeQL flagged this as go/request-forgery — an admin
    (or anyone who compromises the admin account) could point a node
    at internal infrastructure (cloud metadata, RFC1918 ranges, etc.)
    and the panel would dutifully fetch it.
    
    Add util/netsafe with a shared TOCTOU-safe DialContext that
    resolves the host, rejects private/internal IPs unless the
    per-request context whitelists them (per-node AllowPrivateAddress
    flag, plumbed through context.Value), and dials the resolved IP
    directly so the IP that passed the check is the IP we connect to.
    This closes the DNS-rebinding window where a hostname could
    resolve to a public IP at check time and a private one at dial.
    
    Also tighten address validation (NormalizeHost rejects anything
    that isn't a bare hostname or IP literal — no embedded paths,
    userinfo, schemes) and switch URL construction from fmt.Sprintf to
    url.URL{} + net.JoinHostPort so admin-supplied values can't smuggle
    URL components.
    
    custom_geo.go's isBlockedIP now delegates to netsafe so there's
    one source of truth.