Skip to content

feat(backends): implement a generic CAS backend - #1986

Open
sinavir wants to merge 1 commit into
python-social-auth:masterfrom
sinavir:cas
Open

sinavir wants to merge 1 commit into
python-social-auth:masterfrom
sinavir:cas

Conversation

@sinavir

@sinavir sinavir commented Sep 16, 2026 •

Copy link
Copy Markdown

This commit introduces support for the CAS protocol using python-cas library.

It is tested using zulip (for the client) and django-cas-server (for the cas server).

I'm not very confident about how to write the test for this. I'm interested to know if you recommend any code or documentation interesting to get that task done

@nijel

nijel commented Sep 17, 2026

Copy link
Copy Markdown
Member

Thanks for the pull requests. The tests typically mock the authentication API provider, check existing tests for inspiration. Documentation should be added to https://github.com/python-social-auth/social-docs/.

@nijel

nijel commented Sep 17, 2026

Copy link
Copy Markdown
Member

@codex review

Comment thread pyproject.toml Resolved
@codecov

codecov Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.33333% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.03%. Comparing base (191a0a0) to head (00dda2f).
⚠️ Report is 8 commits behind head on master.

Files with missing lines Patch % Lines
social_core/backends/cas_generic.py 87.50% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1986      +/-   ##
==========================================
- Coverage   97.04%   97.03%   -0.01%     
==========================================
  Files         371      373       +2     
  Lines       22455    22515      +60     
  Branches     1354     1356       +2     
==========================================
+ Hits        21791    21847      +56     
- Misses        468      470       +2     
- Partials      196      198       +2     
Flag Coverage Δ
unittests 97.03% <93.33%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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

@nijel

nijel commented Sep 22, 2026

Copy link
Copy Markdown
Member

Thanks for the adjustment, but this still lacks tests and documentation.

@sinavir

sinavir commented Sep 22, 2026

Copy link
Copy Markdown
Author

Yes, I'm currently very busy. It will come at some point.

@sinavir
sinavir force-pushed the cas branch 2 times, most recently from 6739556 to ae3f781 Compare September 27, 2026 15:34
@sinavir
sinavir requested a review from nijel September 27, 2026 15:35
@sinavir
sinavir force-pushed the cas branch 2 times, most recently from 8763ef7 to 40dd2f3 Compare September 30, 2026 09:21
@sinavir

sinavir commented Sep 30, 2026

Copy link
Copy Markdown
Author

Ok, hopefully all lints will pass now

This commit introduce support for the CAS protocol using python-cas
library.
@nijel

nijel commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

I think this is good to merge now (will trigger AI review now to confirm that) besides the missing documentation. Please create a matching pull request against https://github.com/python-social-auth/social-docs.

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T08:38:29.209859Z 00dda2f Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 00dda2fc1c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +60 to +61
ticket = self.strategy.request_data().get("ticket")
user, attributes, _pgtiou = client.verify_ticket(ticket)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Correlate CAS tickets with the initiating session

auth_complete accepts any ticket that validates for the shared static redirect_uri, without checking that this browser started the flow. An attacker can stop the redirect for a ticket issued to their own CAS account and send that callback URL to a victim; an anonymous victim is logged into the attacker's account, and an authenticated victim in an integration that passes the current user to do_complete can associate a fresh attacker CAS identity with the victim's local account. Put a session nonce in the CAS service URL and validate it before accepting the ticket.

AGENTS.md reference: AGENTS.md:L96-L98

Useful? React with 👍 / 👎.

def auth_complete(self, *args, **kwargs):
client = self.get_cas_client()
ticket = self.strategy.request_data().get("ticket")
user, attributes, _pgtiou = client.verify_ticket(ticket)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Route CAS ticket validation through the shared HTTP client

python-cas performs verify_ticket with its own requests call, so every callback bypasses BaseAuth.request: REQUESTS_TIMEOUT, PROXIES, VERIFY_SSL, the configured user agent, and structured HTTP error mapping are ignored. This makes proxy-only deployments fail and lets an unresponsive CAS validation endpoint tie up workers past the configured timeout; perform the validation via the backend's request helper while retaining the CAS response parsing.

AGENTS.md reference: AGENTS.md:L49-L51

Useful? React with 👍 / 👎.

client = self.get_cas_client()
ticket = self.strategy.request_data().get("ticket")
user, attributes, _pgtiou = client.verify_ticket(ticket)
if user is None or attributes is None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Accept successful CAS 1 responses without attributes

When SOCIAL_AUTH_CAS_VERSION is 1, python-cas's CASClientV1 returns (user, None, None) on successful validation because CAS 1 has no attributes, so this condition rejects every valid V1 ticket even though get_cas_client advertises and constructs that client. Treat a non-null user as success and normalize missing attributes to an empty mapping before merging.

Useful? React with 👍 / 👎.

Comment thread pyproject.toml
Comment on lines +80 to +82
cas = [
"python-cas>=1.7.2"
]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Record the new CAS backend in Unreleased

This adds a user-visible backend and installation extra, but CHANGELOG.md has no corresponding entry under Unreleased, so the next release would ship support without the repository's required release record. Add a concise Added entry before merging.

AGENTS.md reference: AGENTS.md:L80-L82

Useful? React with 👍 / 👎.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants