MCPcopy Create free account
hub / github.com/dedsec1121fk/DedSec / _auto_login_from_trusted_device

Function _auto_login_from_trusted_device

Scripts/ButSystem.py:1576–1613  ·  view source on GitHub ↗

If the user is not logged in, attempt auto-login using a trusted-device token cookie. Skips auto-login when 2FA is enabled for that account.

()

Source from the content-addressed store, hash-verified

1574 conn = db_connect()
1575 rows = conn.execute("SELECT username FROM users WHERE is_admin=1 ORDER BY username ASC").fetchall()
1576 conn.close()
1577 return [r["username"] for r in rows]
1578 except Exception:
1579 return []
1580
1581def csrf_token() -> str:
1582 """csrf_token.
1583
1584Internal helper function.
1585
1586This docstring was added automatically to improve maintainability.
1587
1588Returns:
1589 Varies.
1590"""
1591 tok = session.get("_csrf")
1592 if not tok:
1593 tok = secrets.token_urlsafe(32)
1594 session["_csrf"] = tok
1595 return tok
1596
1597def _same_origin_ok() -> bool:
1598 """Best-effort same-origin check using Origin / Referer headers.
1599
1600 Notes:
1601 - We compare only the host:port (netloc) to avoid false failures behind TLS
1602 terminators (e.g., Cloudflared) where the app server may see HTTP.
1603 - If headers are missing, we allow the request.
1604 - If headers are present but malformed/unparseable, we fail closed.
1605 """
1606 from urllib.parse import urlparse
1607
1608 expected = (request.host or "").lower().strip()
1609 if not expected:
1610 return False
1611
1612 origin = (request.headers.get("Origin") or "").strip()
1613 ref = (request.headers.get("Referer") or "").strip()
1614
1615 # If neither header is present, don't block legitimate requests.
1616 if not origin and not ref:

Callers

nothing calls this directly

Calls 8

is_logged_inFunction · 0.70
_trusted_device_lookupFunction · 0.70
user_2fa_enabledFunction · 0.70
current_scopeFunction · 0.70
scope_capacity_okFunction · 0.70
now_zFunction · 0.70
ensure_profile_rowFunction · 0.70
_trusted_device_touchFunction · 0.70

Tested by

no test coverage detected