Skip to content

chore: refacotring http auth - #100

Open
itsoyou wants to merge 1 commit into
mainfrom
syk/rework-http-auth-parsing
Open

chore: refacotring http auth#100
itsoyou wants to merge 1 commit into
mainfrom
syk/rework-http-auth-parsing

Conversation

@itsoyou

@itsoyou itsoyou commented Aug 27, 2026

Copy link
Copy Markdown
Member

SYN-99


Note

Medium Risk
Changes auth config parsing and error types for OAuth introspection/notify HTTP auth, which could break misconfigured deployments that relied on empty types or empty credentials.

Overview
Refactors HTTP auth configuration parsing: NoAuth, BasicAuth, and BearerAuth move from Pydantic BaseModel to pydantic.dataclasses, with min_length=1 on username, password, and token so empty credentials fail validation.

parse_dict_auth and parse_list_auth are removed; dict and list shapes are handled in a single parse_auth, with an AUTH_TYPES map for basic / bearer. Parse failures now raise ValueError with a consistent Auth configuration error: prefix (optional config context in logs and messages), instead of generic Exception / HttpAuth wording.

Behavior tightening: only type: null (or list [null]) yields NoAuth; an empty string type is treated as unknown, not no-auth. Dict configs with extra keys are accepted (extras ignored); list configs still reject extra positional args. pydantic is added as a runtime dependency and pydantic.mypy is enabled in tooling.

Reviewed by Cursor Bugbot for commit 6d5b978. Bugbot is set up for automated code reviews on this repo. Configure here.

@itsoyou
itsoyou requested a review from a team as a code owner August 27, 2026 10:03
@codecov

codecov Bot commented Aug 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.34%. Comparing base (88e4ff0) to head (6d5b978).

Files with missing lines Patch % Lines
synapse_token_authenticator/http_auth.py 95.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #100      +/-   ##
==========================================
- Coverage   76.67%   76.34%   -0.33%     
==========================================
  Files           9        9              
  Lines         763      761       -2     
  Branches      130      126       -4     
==========================================
- Hits          585      581       -4     
- Misses        124      125       +1     
- Partials       54       55       +1     
Files with missing lines Coverage Δ
synapse_token_authenticator/http_auth.py 96.42% <95.00%> (-3.58%) ⬇️

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 88e4ff0...6d5b978. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread synapse_token_authenticator/http_auth.py Outdated
Comment thread synapse_token_authenticator/http_auth.py Outdated
@itsoyou
itsoyou marked this pull request as draft August 27, 2026 10:55
@itsoyou
itsoyou force-pushed the syk/rework-http-auth-parsing branch from e3b191f to 991b5dd Compare August 27, 2026 13:13
@itsoyou
itsoyou marked this pull request as ready for review August 27, 2026 13:13
Comment thread synapse_token_authenticator/http_auth.py Outdated
Comment thread synapse_token_authenticator/http_auth.py
Comment thread synapse_token_authenticator/http_auth.py Outdated

@model_validator(mode="before")
@classmethod
def check_username_and_password_present(cls, data: Any) -> Any:

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.

shouldn't this already be done by pydantic?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ahh good point.


@model_validator(mode="before")
@classmethod
def check_token_present(cls, data: Any) -> Any:

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.

same here for pydantic

else:
logger.error("HttpAuth configuration error: %s", e)
raise e from e
raise TypeError(

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.

This already includes {context}: {HTTP_AUTH_CONFIGURATION_ERROR} prefix, but the except (…, TypeError) below re-wraps it with the same prefix (then appears twice in the logs). Maybe you can raise the bare message here (raise TypeError("Auth parsing failed, expected list or dict")) and let the except add the prefix once.

@itsoyou
itsoyou force-pushed the syk/rework-http-auth-parsing branch from 991b5dd to 6d5b978 Compare August 28, 2026 08:58

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 6d5b978. Configure here.

token: str
@dataclass
class BearerAuth:
token: str = Field(min_length=1)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Dict extras silently ignored

Medium Severity

BasicAuth and BearerAuth dropped extra="forbid" in the move from BaseModel to pydantic dataclasses, so unknown dict keys are discarded instead of failing config load. List-form extras still error via auth(*args), so the same typo is accepted or rejected depending on config shape.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 6d5b978. Configure here.

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.

2 participants