airflow icon indicating copy to clipboard operation
airflow copied to clipboard

AwsAuthManager: requested page (next_url) is dropped during SAML login

Open SachinyadavAug20 opened this issue 2 weeks ago • 2 comments

Under which category would you file this issue?

Providers

Apache Airflow version

main (Airflow 3.0+)

Apache Airflow Provider(s)

amazon

What happened and how to reproduce it?

Issue Description When an unauthenticated user visits a deep link (such as a specific DAG, task run, or log page), Airflow routes them to /auth/login?next=<destination>.

In AwsAuthManager, this destination is completely lost:

  1. AwsAuthManager.get_url_login(next_url=...) ignores the next_url kwarg and returns a bare /auth/login without query parameters (providers/amazon/.../aws_auth_manager.py:540).
  2. Even when next is passed as a query param to /auth/login, _start_login() in providers/amazon/.../routes/login.py does not read or retain it.
  3. Upon completing the SAML authentication round trip at /auth/login_callback, the handler hardcodes a redirect to conf.get("api", "base_url", fallback="/"), always sending users to the home page instead of their requested page.

The same bug was previously resolved for:

  • SimpleAuthManager in #67483 and #67965 (#67476)
  • FabAuthManager in #73134 (#73133)
  • KeycloakAuthManager in #76362

AwsAuthManager is currently the only auth manager where next_url is not preserved.

Steps to reproduce:

  1. Configure Airflow to use AwsAuthManager.
  2. As a logged-out user, navigate to a direct link such as http://localhost:8080/dags/my_dag/runs/run_id/tasks/my_task.
  3. Complete the login flow with the IdP.
  4. After callback, observe that the browser is redirected to / instead of /dags/my_dag/runs/run_id/tasks/my_task.

What you think should happen instead?

  1. AwsAuthManager.get_url_login(next_url=...) should append ?next=<url>.
  2. The login route should validate next using is_safe_url and retain it in a short-lived HTTP-only cookie.
  3. login_callback should redirect to the stored next URL (falling back to [api] base_url if unset or unsafe) and clear the cookie.

Operating System

Linux

Deployment

Other

Are you willing to submit PR?

  • [X] Yes I am willing to submit a PR!

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

SachinyadavAug20 avatar Nov 17 '26 17:11 SachinyadavAug20

Thanks for opening your first issue here! Be sure to follow the issue template! If you are willing to raise PR to address this issue please do so, no need to wait for approval.

boring-cyborg[bot] avatar Nov 17 '26 17:11 boring-cyborg[bot]

Proposed fix:

Follow the same pattern recently merged in KeycloakAuthManager (#76362) and FabAuthManager (#73134):

  1. Preserve next_url query param: AwsAuthManager.get_url_login(next_url=...) --> appends ?next=<url> (via urlencode) when present.

  2. Store safe destination in cookie: User hits /auth/login?next=... --> validate next with is_safe_url(): => If safe: save in a short-lived HTTP-only cookie (_awsam_login_next_url, SameSite=None if HTTPS else Lax, max-age 10m matching login state). => If unsafe or missing: clear/delete any stale _awsam_login_next_url cookie.

  3. Redirect on SAML callback: IdP completes SAML POST to /auth/login_callback --> read _awsam_login_next_url from cookie: => If present & safe: redirect user to next_url (e.g. /dags/...). => If absent or invalid: fallback to [api] base_url. => Clear _awsam_login_next_url cookie (Max-Age=0).

I have the patch and unit tests ready locally (all 95 auth manager tests passing). Opening PR shortly!

SachinyadavAug20 avatar Nov 17 '26 17:11 SachinyadavAug20