Repository navigation
Description
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.eventsObserved (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.goObserved: gmail+calendar readonly: DisableIncludeGrantedScopes=true, calendar-only readonly: DisableIncludeGrantedScopes=false (so the reauth URL carries include_granted_scopes=true).
Cause
- Gmail's service scopes are fixed at
gmail.modify+ both settings scopes (service.go); Calendar has onlycalendarorcalendar.readonly(service.go);--extra-scopesis merged after them (service.go). - Incremental grants are disabled only for read-only/limited modes (auth_add.go).
Reauthnarrows only whenhasLimitedGmailGrantorhasLimitedPhotosGrantmatches (reauth.go), socalendar.readonlyalone is not treated as narrowed.
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.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
clawsweeper commentedon Oct 23, 2026
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
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:
Codex review notes: model internal, reasoning medium; reviewed against f9052a583e87.
Label changes
Label changes:
P2: A specific automatic recovery path fails to preserve a narrowed OAuth request, with no demonstrated outage or completed privilege expansion.impact:security: Incremental authorization can reintroduce previously granted access beyond the recorded read-only scope selection.impact:auth-provider: The defect changes OAuth authorization parameters during refresh-token recovery.issue-rating: 🦞 diamond lobster: Current issue advisory state selects this label.clawsweeper:source-repro: Current issue advisory state selects this label.clawsweeper:no-new-fix-pr: Current issue advisory state selects this label.clawsweeper:needs-product-decision: Current issue advisory state selects this label.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:
internal/googleauth/reauth.go:161For 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:
internal/googleauth/reauth.go:159, f9052a583e87)internal/googleauth/oauth_flow.go:256, f9052a583e87)internal/googleapi/client.go:359, f9052a583e87)internal/googleauth/reauth_test.go:293, f9052a583e87)internal/googleauth/service.go:553, f9052a583e87)How this review workflow works
@clawsweeper re-reviewcomments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.@clawsweeper re-reviewor@clawsweeper re-runon an open PR or issue to request a fresh review only.@clawsweeper reviewto request a fresh review only.@clawsweeper explainto ask for more context, or@clawsweeper stopto stop active automation.Reviewed October 23, 2026, 1:34 PM ET / 17:34 UTC.
fix(auth): preserve read-only Calendar grants during reauthorization (#…
steipete commentedon Oct 26, 2026
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 localmake cipassed. 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.
pkyIntelligence commentedon Nov 11, 2026
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-scopesalready 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 --scopesthat requests exactly the listed scopes (plus identity) and remembers that choice across reauthorization and token export/import. For example,gmail.modifyandcalendar.eventswithoutgmail.readonlyalso being requested.If that is useful to you, I'm happy to open a PR or adapt it to whatever interface you prefer.