Skip to content

Add opt-in --browser-tls (curl_cffi) session to get past Cloudflare 403s (#4) - #9

Open
zenmonkey99 wants to merge 1 commit into
YeomansIII:mainfrom
zenmonkey99:feat/browser-tls-session
Open

zenmonkey99 wants to merge 1 commit into
YeomansIII:mainfrom
zenmonkey99:feat/browser-tls-session

Conversation

@zenmonkey99

Copy link
Copy Markdown

Fixes #4.

Problem

From at least some residential networks (Verizon FiOS in Virginia here), Dominion's API host answers every request made from Python's TLS stack with an HTML !! Error !! Access Denied page and HTTP 403, including unauthenticated GET /. So dompower login dies at the token exchange, refresh 403s with valid tokens, and accounts 403s on GetBpNumber, exactly as reported in #4.

Diagnosis:

Client GET / on prodsvc-dominioncip.smartcmobile.com
aiohttp (any headers / User-Agent) 403 HTML "Access Denied" (server: cloudflare)
curl over HTTP/2 403
curl_cffi impersonate="chrome" 200, and the refresh endpoint returns proper JSON

It is Cloudflare's TLS-fingerprint bot rule, not headers or tokens. Other users evidently aren't hitting it, so this is opt-in.

Change

  • dompower/browser_session.py: BrowserSession, an adapter exposing the subset of aiohttp.ClientSession dompower uses (request/get/post as async context managers, cookie_jar with iteration and update_cookies) on top of curl_cffi.requests.AsyncSession with browser impersonation. DompowerClient and GigyaAuthenticator work unchanged, including cookie save/load for TFA bypass.
  • Optional extra dompower[browser] pulling in curl_cffi. Default install and default behaviour are unchanged.
  • CLI: --browser-tls (or DOMPOWER_BROWSER_TLS=1) uses BrowserSession for every command.
  • README: symptom and usage.
  • Tests: adapter behaviour with a fake curl session (no network); Gigya cookie export/import through the adapter.

Verification

Happy to make this the default, or to wire it into ha-dominion-energy behind a config option, if you'd prefer.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KBfHz3wPHd66NetuAZxtiV

…erprint 403s

Dominion's API host is behind Cloudflare bot protection that, from some
networks, answers every request made with Python's TLS stack with an HTML
"!! Error !! Access Denied" 403, authenticated or not. That is the failure
in YeomansIII#4: login token exchange, token refresh and GetBpNumber all 403 with
valid tokens. The same requests sent with a browser TLS fingerprint reach
the API.

- dompower/browser_session.py: BrowserSession, an adapter exposing the
  subset of aiohttp.ClientSession dompower uses (request/get/post as async
  context managers, cookie_jar) on top of curl_cffi's AsyncSession with
  browser impersonation. Works with DompowerClient and GigyaAuthenticator
  unchanged, including cookie save/load.
- pyproject: optional extra dompower[browser] -> curl_cffi.
- CLI: --browser-tls flag (or DOMPOWER_BROWSER_TLS=1) builds a
  BrowserSession for every command.
- README: document the symptom and the flag.
- tests: adapter behaviour with a fake curl session; Gigya cookie
  export/import through the adapter.

Default behaviour is unchanged; aiohttp remains the default session.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KBfHz3wPHd66NetuAZxtiV

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

accounts / GetBpNumber returns 403 with valid access + refresh tokens (auth-helper + login both fail)

1 participant