Skip to content

auth add: no narrower Gmail/Calendar write grant than gmail.modify+settings and full calendar; Calendar-only read-only reauth re-includes prior grants #1259

Open

Description

@pkyIntelligence

Summary

--readonly already gives a clean read-only Gmail/Calendar grant. For write access there is currently one shape: Gmail adds gmail.settings.basic/gmail.settings.sharing to gmail.modify, Calendar is full calendar, and --extra-scopes can only append. Separately, reauthorizing a Calendar-only read-only token re-includes previously granted scopes, which looks unintended given how Gmail read-only tokens are handled.

Reproduction

Tested at HEAD f9052a583e87637894b72199b9dc2b47cfa7f37a (these auth files are unchanged since v0.46.0). No Google credentials or network requests are needed; the OAuth client is synthetic and only the printed authorization URL is inspected. Set GOG_BIN to the absolute path of a gog binary. Run in Bash:

GOG_BIN=/absolute/path/to/gog
probe=$(mktemp -d)
cat > "$probe/client.json" <<'JSON'
{"installed":{"client_id":"synthetic.apps.googleusercontent.com","client_secret":"synthetic","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","redirect_uris":["http://localhost"]}}
JSON

run_gog() {
  env -i PATH=/usr/bin:/bin HOME="$probe/home" GOG_HOME="$probe/gog" \
    DBUS_SESSION_BUS_ADDRESS=disabled: \
    XDG_CONFIG_HOME="$probe/config" XDG_DATA_HOME="$probe/data" \
    GOG_KEYRING_BACKEND=file GOG_KEYRING_PASSWORD=synthetic \
    "$GOG_BIN" "$@"
}
show_url() {
  echo "== $*"
  run_gog "$@" --remote --step 1 2>/dev/null |
    sed -n 's/^auth_url[[:space:]]*//p' | tr '?&' '\n\n' |
    grep -E '^(scope|include_granted_scopes)=' |
    sed 's/%3A/:/g; s/%2F/\//g; s/+/ /g'
}

run_gog auth credentials "$probe/client.json" >/dev/null
show_url auth add probe@example.invalid --services gmail,calendar
show_url --readonly auth add probe@example.invalid --services gmail,calendar
show_url auth add probe@example.invalid --services gmail,calendar \
  --gmail-scope readonly \
  --extra-scopes https://www.googleapis.com/auth/calendar.events

Observed (identity scopes openid/email/userinfo.email appear in every request):

== auth add ... --services gmail,calendar
include_granted_scopes=true
scope=... calendar gmail.modify gmail.settings.basic gmail.settings.sharing ...
== --readonly auth add ... --services gmail,calendar
scope=... calendar.readonly gmail.readonly ...
== auth add ... --gmail-scope readonly --extra-scopes .../calendar.events
scope=... calendar calendar.events gmail.readonly ...

The last case still requests full calendar alongside calendar.events.

Reauth narrowing, offline with injected stubs:

# From a gogcli checkout at the commit above:
cat > internal/googleauth/reauth_readonly_probe_test.go <<'EOF'
package googleauth

import (
	"context"
	"io"
	"testing"
	"time"

	"github.com/openclaw/gogcli/internal/secrets"
)

func TestReauthReadonlyProbe(t *testing.T) {
	for name, scopes := range map[string][]string{
		"gmail+calendar readonly": {"openid", "https://www.googleapis.com/auth/gmail.readonly", "https://www.googleapis.com/auth/calendar.readonly"},
		"calendar-only readonly":  {"openid", "https://www.googleapis.com/auth/calendar.readonly"},
	} {
		tok := secrets.Token{Email: "probe@example.invalid", Scopes: scopes}
		var got AuthorizeOptions
		_, err := Reauth(context.Background(), ReauthOptions{
			Email: tok.Email, Client: "default", Scopes: scopes, StoredToken: &tok, Stderr: io.Discard,
			Confirm:       func(context.Context, string) (bool, error) { return true, nil },
			AuthorizeFunc: func(_ context.Context, o AuthorizeOptions) (string, error) { got = o; return "rt", nil },
			FetchIdentityFunc: func(context.Context, string, string, []string, time.Duration) (Identity, error) {
				return Identity{Email: tok.Email}, nil
			},
		})
		t.Logf("%s: err=%v DisableIncludeGrantedScopes=%v", name, err, got.DisableIncludeGrantedScopes)
	}
}
EOF
go test -count=1 -run TestReauthReadonlyProbe -v ./internal/googleauth
rm internal/googleauth/reauth_readonly_probe_test.go

Observed: gmail+calendar readonly: DisableIncludeGrantedScopes=true, calendar-only readonly: DisableIncludeGrantedScopes=false (so the reauth URL carries include_granted_scopes=true).

Cause

Prior work: #420 added append-only --extra-scopes; #1033 added the read-send preset.

Suggestion

The reauth case looks like a small bug; happy to send a fix for that on its own if useful.

On the write side, one idea: an optional narrower write grant might be useful for users who want least-privilege access. If that fits the project's direction, we'd be glad to follow whatever shape you prefer (for example more presets in the style of read-send, or something else entirely).

Investigated and reproduced with AI assistance (the Astrarch agent team); the reproduction was verified on a real host.

Activity

  1. added
    P2Normal priority bug or improvement with limited blast radius.
    clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.
    clawsweeper:needs-security-reviewClawSweeper marked this issue as needing security-sensitive review.
    clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.
    clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.
    impact:auth-providerThis issue is about auth, provider routing, model choice, or SecretRef resolution.
    impact:securityThis issue is about security boundaries, credentials, authz, sandboxing, or sensitive data.
    issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.
    on Oct 23, 2026
  2. clawsweeper commented on Oct 23, 2026

    @clawsweeper
    Contributor

    Codex review: this still needs some work.

    Summary
    Current main still requests incremental authorization when automatically reauthorizing a Calendar-only read-only token, establishing a concrete defect despite the broader write-preset request needing qualification.

    Reproducibility: Current source proves that a stored token containing openid and calendar.readonly produces DisableIncludeGrantedScopes=false and therefore include_granted_scopes=true; the supplied offline probe agrees, but no tests or live authorization were run during this read-only review.

    Maintainer decision needed

    • Question: Should narrower write authorization use additional named presets, or continue through the existing read-only base plus extra scopes?
    • Recommendation: Repair recovery and document existing composition: Fix Calendar-only read-only reauth independently and clarify current Gmail presets and read-only-base scope composition.
    • Why: Current scope composition already supports some narrower write combinations, while new Calendar or Gmail presets would introduce additional supported modes beyond the recovery repair.

    Next step
    Review the OAuth boundary and establish a failing Calendar-only read-only reauth regression before repairing prior-grant inclusion, with optional presets handled separately.

    Security
    Needs attention: Calendar-only read-only recovery requests inclusion of prior grants, requiring review of the OAuth permission boundary.

    Review details

    Best possible solution:

    Preserve Calendar-only read-only grants during automatic recovery while retaining broad-grant compatibility and deciding optional write presets separately.

    Do we have a high-confidence way to reproduce the issue?

    Current source proves that a stored token containing openid and calendar.readonly produces DisableIncludeGrantedScopes=false and therefore include_granted_scopes=true; the supplied offline probe agrees, but no tests or live authorization were run during this read-only review.

    Is this the best way to solve the issue?

    A focused Calendar recovery correction is justified independently of new presets; the broader request should acknowledge existing send/read-send modes and read-only-base plus extra-scope composition before adding another public option.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • The OAuth request includes prior grants, but this review did not observe Google issuing a broader replacement token.
    • The report combines a bounded recovery defect with optional write presets whose supported operations and public interface remain undecided.

    Codex review notes: model internal, reasoning medium; reviewed against f9052a583e87.

    Label changes

    Label changes:

    • add P2: A specific automatic recovery path fails to preserve a narrowed OAuth request, with no demonstrated outage or completed privilege expansion.
    • add impact:security: Incremental authorization can reintroduce previously granted access beyond the recorded read-only scope selection.
    • add impact:auth-provider: The defect changes OAuth authorization parameters during refresh-token recovery.
    • add issue-rating: 🦞 diamond lobster: Current issue advisory state selects this label.
    • add clawsweeper:source-repro: Current issue advisory state selects this label.
    • add clawsweeper:no-new-fix-pr: Current issue advisory state selects this label.
    • add clawsweeper:needs-product-decision: Current issue advisory state selects this label.
    • add clawsweeper:needs-security-review: Current issue advisory state selects this label.

    Label justifications:

    • P2: A specific automatic recovery path fails to preserve a narrowed OAuth request, with no demonstrated outage or completed privilege expansion.
    • impact:auth-provider: The defect changes OAuth authorization parameters during refresh-token recovery.
    • impact:security: Incremental authorization can reintroduce previously granted access beyond the recorded read-only scope selection.
    Evidence reviewed

    Security concerns:

    • [medium] Prior grants can escape the recorded read-only selection — internal/googleauth/reauth.go:161
      For a stored Calendar-only read-only token, Reauth leaves incremental authorization enabled while returning metadata containing only the requested stored scopes; a wider provider grant remains possible, although this review did not demonstrate completed escalation and browser authorization remains required.
      Confidence: 0.96

    What I checked:

    • Current default branch: GitHub main and the review checkout both resolve to f9052a5; the checkout remained clean. (f9052a583e87)
    • Calendar read-only omission: Reauth derives DisableIncludeGrantedScopes only from limited Gmail or Photos scopes; calendar.readonly alone matches neither helper. (internal/googleauth/reauth.go:159, f9052a583e87)
    • Observable authorization request: Authorize negates DisableIncludeGrantedScopes when constructing the URL, and authURLParams adds include_granted_scopes=true when enabled; existing URL tests verify that mapping. (internal/googleauth/oauth_flow.go:256, f9052a583e87)
    • Shipped recovery path: The token-source recovery closure supplies stored token metadata to the configured Reauth dependency; root command wiring invokes googleauth.Reauth with that metadata. (internal/googleapi/client.go:359, f9052a583e87)
    • Existing preservation controls: Tests cover limited Gmail, read-only Photos, broad stored multi-service grants, and missing scope metadata, but omit Calendar-only read-only recovery. (internal/googleauth/reauth_test.go:293, f9052a583e87)
    • Write-grant qualification: Gmail already supports send and read-send without modify/settings scopes; Calendar selects calendar.readonly under Readonly, and ExtraScopes is merged afterward without replacing the base scopes. (internal/googleauth/service.go:553, f9052a583e87)
    How this review workflow works
    • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
    • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
    • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
    • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
    • Maintainers can also comment @clawsweeper review to request a fresh review only.
    • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge; those execution lanes are retired.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

    Reviewed October 23, 2026, 1:34 PM ET / 17:34 UTC.

  3. steipete commented on Oct 26, 2026

    @steipete
    Collaborator

    The Calendar read-only reauthorization bug is fixed by #1265, merged as 4d68f06. Stored read-only grants now omit incremental authorization, including mixed-service grants and read-only Calendar plus event-write scopes; full Calendar grants retain their existing behavior.

    Proof: authorization-URL regression tests, go test ./internal/googleauth -run TestReauth -count=1, and local make ci passed. CI on the exact PR head passed Linux, minimum-Go, Windows, macOS, and Worker checks; the container and CodeQL checks also passed.

    Thanks @pkyIntelligence for the reproduction. Leaving this issue open for the separate narrower-write-grant proposal.

  4. pkyIntelligence commented on Nov 11, 2026

    @pkyIntelligence
    ContributorAuthor

    Thanks for fixing the Calendar read-only reauthorization in #1265.

    A correction to my original report: on current main, a read-only base plus --extra-scopes already gives narrower Gmail/Calendar write access without the settings and full-Calendar defaults. That covers most of what I asked for here.

    The one thing we still do differently downstream is an optional auth add --scopes that requests exactly the listed scopes (plus identity) and remembers that choice across reauthorization and token export/import. For example, gmail.modify and calendar.events without gmail.readonly also being requested.

    If that is useful to you, I'm happy to open a PR or adapt it to whatever interface you prefer.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal priority bug or improvement with limited blast radius.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:needs-security-reviewClawSweeper marked this issue as needing security-sensitive review.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:auth-providerThis issue is about auth, provider routing, model choice, or SecretRef resolution.impact:securityThis issue is about security boundaries, credentials, authz, sandboxing, or sensitive data.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions