Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

pcloud: fix OAuth config accepting callbacks without state GHSA-hvpr-p4pv-4f46 CVE-PENDING

Nick Craig-Wooda53fdac5ec1f
diff --git a/backend/pcloud/pcloud.go b/backend/pcloud/pcloud.go
index 95043a2f2..87b6cfec0 100644
--- a/backend/pcloud/pcloud.go
+++ b/backend/pcloud/pcloud.go
@@ -95,7 +95,6 @@ func init() {
return oauthutil.ConfigOut("", &oauthutil.Options{
OAuth2Config: oauthConfig,
CheckAuth: checkAuth,
- StateBlankOK: true, // pCloud seems to drop the state parameter now - see #4210
})
},
Options: append(oauthutil.SharedOptions, []fs.Option{{
diff --git a/lib/oauthutil/oauthutil.go b/lib/oauthutil/oauthutil.go
index 37d2f11cc..d21efe059 100644
--- a/lib/oauthutil/oauthutil.go
+++ b/lib/oauthutil/oauthutil.go
@@ -612,7 +612,6 @@ type Options struct {
NoOffline bool // If set then "access_type=offline" parameter is not passed
CheckAuth CheckAuthFn // When the AuthResult is known the checkAuth function is called if set
OAuth2Opts []oauth2.AuthCodeOption // extra oauth2 options
- StateBlankOK bool // If set, state returned as "" is deemed to be OK
}
// ConfigOut returns a config item suitable for the backend config
@@ -1097,8 +1096,13 @@ func (s *authServer) handleAuth(w http.ResponseWriter, req *http.Request) {
}
// check state
+ //
+ // This is the only thing which ties the callback to the flow
+ // rclone started, so a request without it must be rejected -
+ // any web page open in the browser can make a request to the
+ // local auth server.
state := req.Form.Get("state")
- if state != s.state && !(state == "" && s.opt.StateBlankOK) {
+ if state != s.state {
reply(http.StatusBadRequest, &AuthResult{
Name: "Auth state doesn't match",
Description: fmt.Sprintf("Expecting %q got %q", s.state, state),
diff --git a/lib/oauthutil/oauthutil_test.go b/lib/oauthutil/oauthutil_test.go
new file mode 100644
index 000000000..d7bcdcce1
--- /dev/null
+++ b/lib/oauthutil/oauthutil_test.go
@@ -0,0 +1,42 @@
+package oauthutil
+
+import (
+ "net/http"
+ "net/http/httptest"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+// TestAuthServerHandleAuth checks that only a callback carrying the
+// random state may complete the flow, since the callback is an
+// unauthenticated request any web page in the user's browser can make.
+func TestAuthServerHandleAuth(t *testing.T) {
+ for _, test := range []struct {
+ name string
+ query string
+ wantStatus int
+ wantOK bool
+ }{
+ {"CorrectState", "?code=CODE&state=correct-state", http.StatusOK, true},
+ {"WrongState", "?code=CODE&state=wrong-state", http.StatusBadRequest, false},
+ {"BlankState", "?code=CODE&state=", http.StatusBadRequest, false},
+ {"MissingState", "?code=CODE", http.StatusBadRequest, false},
+ {"MissingCode", "?state=correct-state", http.StatusBadRequest, false},
+ } {
+ t.Run(test.name, func(t *testing.T) {
+ s := newAuthServer(&Options{}, "", "correct-state", "")
+ w := httptest.NewRecorder()
+ s.handleAuth(w, httptest.NewRequest("GET", "/"+test.query, nil))
+ assert.Equal(t, test.wantStatus, w.Code)
+ result := <-s.result
+ assert.Equal(t, test.wantOK, result.OK)
+ if test.wantOK {
+ assert.Equal(t, "CODE", result.Code)
+ assert.Equal(t, "CODE", result.Form.Get("code"))
+ } else {
+ assert.Equal(t, "", result.Code)
+ }
+ })
+ }
+}