Skip to content

fix(dataviewer): fail closed on incomplete auth; honor CORS wildcards - #2071

Merged
Jamie Kim (jkim323) merged 10 commits into
microsoft:mainfrom
mangeshraut712:tip/dataviewer-auth-cors-1939
Nov 17, 2026
Merged

Jamie Kim (jkim323) merged 10 commits into
microsoft:mainfrom
mangeshraut712:tip/dataviewer-auth-cors-1939

Conversation

@mangeshraut712

Copy link
Copy Markdown
Contributor

Summary

  • Require DATAVIEWER_AZURE_TENANT_ID / DATAVIEWER_AZURE_CLIENT_ID for azure_ad and DATAVIEWER_AUTH0_DOMAIN / DATAVIEWER_AUTH0_AUDIENCE for auth0 at provider construction (fail closed instead of starting with empty issuer/audience)
  • Split CORS_ORIGINS entries containing * into allow_origin_regex so Terraform's https://*.<env domain> value matches real Origin headers under Starlette CORSMiddleware
  • Unknown providers already raised; covered by existing test

Tests

  • test_azure_ad_missing_settings_fail_closed / test_auth0_missing_settings_fail_closed
  • test_cors_wildcard_origins_become_regex
  • Full test_auth_unit.py + test_config.py: 67 passed

Fixes #1939

Require azure_ad/auth0 settings at provider construction instead of
starting with empty tenant/domain values. Split CORS_ORIGINS entries
that contain '*' into allow_origin_regex so Terraform's
https://*.<env domain> pattern matches real Origin headers.

Fixes microsoft#1939

@bindsi Marcel Bindseil (bindsi) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CORS wildcard implementation behaves correctly for the intended deployed origin shape, but the authentication change does not yet satisfy issue #1939's startup contract. Azure AD, Auth0, and unknown-provider validation remain lazy: lifespan startup succeeds, then the first protected request raises. Please construct the selected provider during startup and add lifespan regressions. Also add middleware-level CORS tests, refresh the blocked branch from current main, and publish the supported backend validation result for the final head.

@mangeshraut712

Copy link
Copy Markdown
Contributor Author

Thanks for the review. An isolated probe at 70a7fac confirms the startup issue: Azure AD/Auth0 and unknown providers are only constructed on the first protected request.

I’m blocked on the documented pinned RPI bootstrap: this environment has gh 2.46.0, which does not provide gh skill. Is there a supported alternative for completing that bootstrap?

No follow-up changes have been pushed. The startup fix, lifespan and middleware CORS regressions, main refresh, and supported backend validation are still pending.

Construct the selected provider in the lifespan hook for every provider,
not only easy_auth, so azure_ad/auth0 with missing settings and unknown
DATAVIEWER_AUTH_PROVIDER values fail at startup instead of on the first
protected request. Startup still skips provider construction when local
auth is disabled for a non-hosted provider, matching require_auth.

Add lifespan regressions for missing JWT settings, an unknown provider,
eager JWT provider construction and the disabled local case, plus
middleware-level CORS tests against the real app for wildcard and
literal origins.

Refs microsoft#1939
@mangeshraut712

Copy link
Copy Markdown
Contributor Author

Marcel Bindseil (@bindsi) Pushed 96e534d, which also merges current main (95b1492).

  • Startup: the lifespan hook now builds the selected provider for every provider, not only easy_auth. azure_ad/auth0 with missing settings and unknown DATAVIEWER_AUTH_PROVIDER values now fail before the app serves. The one skip is DATAVIEWER_AUTH_DISABLED=true with a non-hosted provider, where require_auth never builds a provider either. The function is renamed to validate_auth_configuration since it is no longer hosted-only.
  • Lifespan regressions in tests/api/test_auth.py: missing JWT settings (both providers), unknown provider, JWT provider built before the first request, and the disabled local case. The five failure cases fail on 70a7fac and pass on 96e534d.
  • Middleware CORS tests in tests/api/test_cors.py reload the real app with a wildcard CORS_ORIGINS: preflight and simple requests echo the wildcard and literal origins; other domains, an appended suffix and a non-dot host are rejected.

Backend validation on 96e534d (Linux, Python 3.12.13, frozen uv env):

  • npm run test:backend: 2354 passed, 1 skipped (2342 passed before these changes).
  • ruff check src tests and ruff format --check src tests: clean.
  • npm run lint:backend exits with E902 because it lints scripts/, and data-management/viewer/backend/scripts does not exist on main either. That is unrelated to this PR, so I ran the same ruff check on src tests.

The RPI bootstrap question from my last comment no longer applies, since it only covers the Copilot cloud-agent setup.

@codecov-commenter

Codecov Comments Bot (codecov-commenter) commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 30 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.12%. Comparing base (e827083) to head (70f8a65).

Files with missing lines Patch % Lines
data-management/viewer/backend/src/api/config.py 0.00% 16 Missing ⚠️
data-management/viewer/backend/src/api/auth.py 0.00% 13 Missing ⚠️
data-management/viewer/backend/src/api/main.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2071      +/-   ##
==========================================
- Coverage   87.29%   87.12%   -0.18%     
==========================================
  Files         402      389      -13     
  Lines       52480    51406    -1074     
  Branches     7309     7167     -142     
==========================================
- Hits        45814    44785    -1029     
+ Misses       5365     5352      -13     
+ Partials     1301     1269      -32     
Flag Coverage Δ *Carryforward flag
docusaurus 89.13% <ø> (ø) Carriedforward from e827083
go 100.00% <ø> (ø)
pester 88.40% <ø> (ø) Carriedforward from e827083
pytest-accessibility 82.41% <ø> (ø)
pytest-curation 95.90% <ø> (ø) Carriedforward from e827083
pytest-data-pipeline 100.00% <ø> (ø) Carriedforward from e827083
pytest-dataset-io 97.48% <ø> (ø) Carriedforward from e827083
pytest-dataviewer 91.55% <ø> (-0.01%) ⬇️ Carriedforward from e827083
pytest-dm-tools 93.20% <ø> (ø) Carriedforward from e827083
pytest-evaluation 79.45% <ø> (ø)
pytest-fuzz 1.74% <0.00%> (-0.01%) ⬇️
pytest-inference 99.16% <ø> (ø) Carriedforward from e827083
pytest-shared-ci 100.00% <ø> (ø) Carriedforward from e827083
pytest-training 91.79% <ø> (ø) Carriedforward from e827083
pytest-vlm-judge ∅ <ø> (∅) Carriedforward from e827083
vitest 92.83% <ø> (ø) Carriedforward from e827083
vitest-app 87.50% <ø> (ø) Carriedforward from e827083
vitest-components 91.55% <ø> (ø) Carriedforward from e827083
vitest-features 90.33% <ø> (ø) Carriedforward from e827083
vitest-lib 96.06% <ø> (ø) Carriedforward from e827083
vitest-state 94.13% <ø> (ø) Carriedforward from e827083

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
data-management/viewer/backend/src/api/main.py 95.03% <0.00%> (-0.63%) ⬇️
data-management/viewer/backend/src/api/auth.py 93.18% <0.00%> (-3.84%) ⬇️
data-management/viewer/backend/src/api/config.py 88.95% <0.00%> (-8.52%) ⬇️

... and 13 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jkim323
Jamie Kim (jkim323) added this pull request to the merge queue Nov 17, 2026
Merged via the queue into microsoft:main with commit 5bcb0f6 Nov 17, 2026
72 checks passed
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.

fix(dataviewer): unknown auth provider falls back silently; CORS wildcard origin never matches

4 participants