[GH-ISSUE #5025] OIDC "consent" (hasAlreadyConsented) does not take into consideration if the scope have changed #10143

Closed
opened 2026-04-13 06:04:54 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @jippi on GitHub (Oct 1, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/5025

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Request scope openid profile (user consents)
  2. Request scope openid profile email and the consent screen is bypassed entirely

The scopes field is not updated to reflect email added, but the oauth access tokens table for the new token now has openid profile email instead - basically allowing escalating permissions without further consent

Current vs. Expected behavior

Expanding consent should require a new consent prompt

Today this does not happen

What version of Better Auth are you using?

1.3.24

System info

N/A

Which area(s) are affected? (Select all that apply)

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
});

Additional context

No response

Originally created by @jippi on GitHub (Oct 1, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/5025 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Request scope `openid profile` (user consents) 2. Request scope `openid profile email` and the consent screen is bypassed entirely The `scopes` field is not updated to reflect `email` added, but the `oauth access tokens` table for the new token now has `openid profile email` instead - basically allowing escalating permissions without further consent ### Current vs. Expected behavior Expanding consent should require a new consent prompt Today this does not happen ### What version of Better Auth are you using? 1.3.24 ### System info ```bash N/A ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, }); ``` ### Additional context _No response_
GiteaMirror added the lockedbug labels 2026-04-13 06:04:54 -05:00
Author
Owner

@jippi commented on GitHub (Oct 1, 2025):

Specifically, 19f39cb400/packages/better-auth/src/plugins/oidc-provider/authorize.ts (L191C8-L191C27) should include scope in the check to see if consent has happened - or compare the consent value in DB and new scopes and return false if not the same

<!-- gh-comment-id:3357747399 --> @jippi commented on GitHub (Oct 1, 2025): Specifically, https://github.com/better-auth/better-auth/blob/19f39cb400d1b7afe925528bb58bccb8c3f077c3/packages/better-auth/src/plugins/oidc-provider/authorize.ts#L191C8-L191C27 should include `scope` in the check to see if consent has happened - or compare the consent value in DB and new scopes and return false if not the same
Author
Owner

@dosubot[bot] commented on GitHub (Oct 1, 2025):

You're correct—the current consent logic only checks if the user has previously consented for a client, but it does not compare the requested scopes with those already granted. This means users can escalate permissions without further consent, which is not aligned with OAuth2/OIDC best practices. Consent records do store the scopes as a space-separated string, but the validation step does not use this field to check for scope changes or expansions source.

To fix this, update the consent check to retrieve the previously consented scopes from the database and compare them to the newly requested scopes. If the new request includes any scopes that weren't previously granted, prompt for consent again. You may want to normalize both sets (e.g., split, trim, sort, and deduplicate) before comparing. There are currently no helper utilities for scope set comparison, so you’ll need to implement this logic directly.

This change will ensure that users are prompted for consent whenever a client requests additional scopes, preventing silent permission escalation and aligning with standard OAuth2/OIDC consent flows.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

<!-- gh-comment-id:3357764550 --> @dosubot[bot] commented on GitHub (Oct 1, 2025): <!-- Answer --> You're correct—the current consent logic only checks if the user has previously consented for a client, but it does not compare the requested scopes with those already granted. This means users can escalate permissions without further consent, which is not aligned with OAuth2/OIDC best practices. Consent records do store the scopes as a space-separated string, but the validation step does not use this field to check for scope changes or expansions [source](https://github.com/better-auth/better-auth/blob/f6cbdcc84ee5d2971fdcc8b23ff7c174f88cf45b/packages/better-auth/src/plugins/oidc-provider/authorize.ts). To fix this, update the consent check to retrieve the previously consented scopes from the database and compare them to the newly requested scopes. If the new request includes any scopes that weren't previously granted, prompt for consent again. You may want to normalize both sets (e.g., split, trim, sort, and deduplicate) before comparing. There are currently no helper utilities for scope set comparison, so you’ll need to implement this logic directly. This change will ensure that users are prompted for consent whenever a client requests additional scopes, preventing silent permission escalation and aligning with standard OAuth2/OIDC consent flows. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/878276ea-5be2-4a62-ab71-54d027cf68a0?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/878276ea-5be2-4a62-ab71-54d027cf68a0?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/878276ea-5be2-4a62-ab71-54d027cf68a0?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/878276ea-5be2-4a62-ab71-54d027cf68a0?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/878276ea-5be2-4a62-ab71-54d027cf68a0?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/878276ea-5be2-4a62-ab71-54d027cf68a0?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/878276ea-5be2-4a62-ab71-54d027cf68a0?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/5025)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#10143