alandtse / alandtse/alexa_media_player

[Bug]: Relative /ax/claim form action causes InvalidUrlClientError during setup

未关闭
#3,544 4 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
2k
派生
345
平均合并
8 天 15 小时
30 天内合并 PR
4

描述

### Describe the bug

An existing Alexa Media Player account for `amazon.co.uk` fails setup when Amazon returns a relative login form action such as `/ax/claim?...`.

In `AlexaLogin._process_page()`, the generic form branch assigns `site = formsite`. The relative string is later passed to `aiohttp.ClientSession.post()`, which requires an absolute URL and raises `InvalidUrlClientError`. Home Assistant then leaves the config entry in `setup_error`.

### To Reproduce

1. Use an existing `amazon.co.uk` Alexa Media Player entry whose Amazon session needs login processing.
2. Restart or reload Alexa Media Player on the versions below.
3. If Amazon's response contains a sign-in form whose action is `/ax/claim?...`, setup fails with the exception below.

The failing behavior can also be reproduced deterministically at library level by passing a sign-in form with `action="/ax/claim?arb=test"` and a current page URL of `https://www.amazon.co.uk/ap/signin` to `_process_page()`. It returns `/ax/claim?arb=test` rather than an absolute URL.

### Expected behavior

Relative form actions should be resolved against the current page URL before they are passed to aiohttp. In the deterministic example, `_process_page()` should return `https://www.amazon.co.uk/ax/claim?arb=test`, allowing setup to continue.

### Screenshots

Not attached to avoid exposing account details. The integration page displayed **Failed to set up** for the account entry.

### Home Assistant Version

2026.8.3

### Alexa Media Player Version

5.15.7

### Alexa Media Player API library Version

1.29.25

### Have you entered a 52-character key for Amazon 2SV via Authenticator App login?

Yes

### Is the HA core integration Alexa Devices installed?

Yes

### Amazon Domain

amazon.co.uk (UK)

### Amazon Domain (if Other)

Not applicable

### Debug Logs (alexa_media & alexapy)

```text
Error setting up entry - amazon.co.uk for alexa_media
...
File "/usr/local/lib/python3.14/site-packages/alexapy/alexalogin.py", line 1134, in login
await self._session.post(site, ...)
...
aiohttp.client_exceptions.InvalidUrlClientError: /ax/claim?...
```

The same exception occurred on two setup attempts before applying the patch. Account identifiers and URL query values have been redacted.

### Additional context

The generic branch currently does this:

```python
elif formsite:
site = formsite
```

This minimal change fixes both the deterministic regression and the live config entry:

```diff
elif formsite:
- site = formsite
+ site = site_url.join(URL(formsite))
```

Verification performed:

- Before the change, the focused regression test failed because `_process_page()` returned `/ax/claim?arb=test`.
- After the change, the focused test and 33 existing non-server tests passed.
- The patched module compiled successfully in the Home Assistant Core container.
- After a Core restart, the Alexa Media Player config entry changed from `setup_error` to `loaded`; the `/ax/claim` exception did not recur.

This appears to be a recurrence of the relative form-action bug class reported in #2418, which involved `/errors/validateCaptcha`, but the new path is `/ax/claim` and the generic form branch still permits any relative action through unchanged.

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。