aws-cli icon indicating copy to clipboard operation
aws-cli copied to clipboard

aws login: stale browser cookies cause 400 Bad Request — CLI hangs until timeout with no feedback

Open AlRos14 opened this issue 8 months ago • 26 comments

Describe the bug

When aws login opens the browser and stale AWS session cookies are present, the signin portal returns 400 Bad Request directly to the browser. The CLI's local callback server (127.0.0.1:PORT) never receives a redirect, so the process hangs silently for up to 10 minutes with no feedback before failing.

Expected Behavior

When a browser session cookie is detected but the underlying session has expired, the server should redirect the browser to the login page so the user can re-authenticate and complete the OAuth flow naturally — rather than returning 400.

If redirecting to the login page is not possible, the server should communicate the failure back through the redirect_uri with an error parameter as required by RFC 6749 §4.1.2.1, allowing the CLI to surface a meaningful error immediately.

Current Behavior

  1. CLI starts a local callback server at http://127.0.0.1:PORT/oauth/callback
  2. CLI opens /v1/authorize?...&redirect_uri=http://127.0.0.1:PORT/oauth/callback in the browser
  3. The server detects existing browser session cookies and attempts to reuse the session
  4. Browser is redirected to /v1/sessions?...
  5. Browser is redirected to /oauth?iam_user=true&backwards_compatible=true&...
  6. Server returns 400 Bad Request — browser shows an error page and stops
  7. The redirect_uri is never called; the CLI hangs for up to 10 minutes then raises PendingAuthorizationExpiredError with no useful message

Reproduction Steps

  1. Sign into the AWS Management Console in your browser (sets session cookies)
  2. Wait for the server-side session to expire (the browser cookies remain)
  3. Run aws login
  4. The browser opens and immediately shows a 400 error page
  5. The CLI prints nothing — it hangs until the 10-minute _OVERALL_TIMEOUT in AuthCodeFetcher.get_auth_code_and_state(), then raises PendingAuthorizationExpiredError

Possible Solution

Replace the current error-based stale cookie handling with a proper authentication redirect flow. Instead of surfacing a 400 error to the user when a stale cookie is detected, the server should transparently redirect the user through the login page so the CLI can obtain a fresh token without requiring manual intervention. Current flow (broken): stale cookie detected → try session reuse → error 400 Proposed flow: stale cookie detected → redirect to login page → user authenticates → redirect_uri called with auth code → CLI exchanges code for token

CLI version used

aws-cli/2.34.23

Environment details (OS name and version, etc.)

Python/3.14.3 Linux/6.8.0-106-generic exe/x86_64.ubuntu.24 OS: Ubuntu 24.04 Browser: Brave (Chromium-based) Region: eu-south-2

AlRos14 avatar Apr 03 '26 10:04 AlRos14

Hello @AlRos14, thank you for reaching out. I am investigating this issue and I will update back as soon as I have updates.

adev-code avatar Apr 03 '26 22:04 adev-code

Hello @AlRos14! After investigating, it seems that the 400 Error is coming from the SignIn service and does not redirect to the login page. I have reached out to the SignIn team in this regard and will update you as soon as there any updates form the team.

Internal Ref: P411663187

adev-code avatar Apr 08 '26 20:04 adev-code

Hi @adev-code, do we have any update regarding this issue ?

phuc-ppt avatar May 07 '26 04:05 phuc-ppt

More than 2 months now and no update! When can we expect this to be worked on as it is a major headache.

genifycom avatar Jun 16 '26 14:06 genifycom

One of my team members is experiencing this error now. Tried it with incognito mode and still got the same error. And regardless of browser used.

angsm avatar Jun 17 '26 07:06 angsm

Same issue here, I've been scratching my head the whole day trying to figure out the issue. So this could be an issue on AWS team huh?

$ aws --version
aws-cli/2.35.11 Python/3.14.5 Darwin/25.2.0 exe/arm64

butadpj avatar Jun 25 '26 13:06 butadpj

Same issue! Any progress now?

SnakeLil avatar Jun 26 '26 02:06 SnakeLil

I am having the same issue

SaigaGentil avatar Jun 28 '26 20:06 SaigaGentil

Having same issue

0x9ef avatar Jul 01 '26 11:07 0x9ef

Having same issue

Imaisen17 avatar Jul 02 '26 18:07 Imaisen17

+1 to the issue. unable to login.

BhargavSatya avatar Jul 04 '26 04:07 BhargavSatya

+1 Here as well.

thatMacAdmin avatar Jul 04 '26 15:07 thatMacAdmin

Same here. There's no indication of why this is failing. This effectively prevents me from using the AWS CLI entirely

tom-galvin avatar Jul 09 '26 02:07 tom-galvin

+1

AndrewGrachov avatar Jul 13 '26 20:07 AndrewGrachov

+1 same issue - although switching to a different account might fix it for me

rudi-lgtm avatar Jul 17 '26 13:07 rudi-lgtm

refer to https://repost.aws/questions/QUmrioyrpWRDGdEjs20O0tQQ/400-bad-request-when-logging-in-using-aws-cli, IAM account would require SignInLocalDevelopmentAccess policy to login.

HernandoR avatar Jul 20 '26 06:07 HernandoR

@HernandoR

Thanks for sharing this. I’m not sure the permission itself explains the 400 Bad Request, though. I have been experiencing the same issue even with administrator permissions.

SignInLocalDevelopmentAccess is clearly required for aws login, but the failure described here appears to happen earlier in the browser-side session/OAuth flow. It may be that adding the policy coincided with the AWS session or cookies being refreshed, which then made the next attempt work.

The issue has also been open for almost three months, and so far the only update from AWS has been that it was referred internally. It would be helpful to know whether the underlying service team has identified the cause or if a fix is being worked on.

AlRos14 avatar Jul 24 '26 16:07 AlRos14

I am also having this issue. There's seriously no update after 4 months?

eschos24 avatar Aug 18 '26 04:08 eschos24

Same issue here. Waiting for the updates :(

gui-uchoa avatar Sep 09 '26 13:09 gui-uchoa

Classic AWS

DraganAndrei avatar Sep 22 '26 08:09 DraganAndrei