Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

Fix mass assignment vulnerability in sign-in verification codes

Matt Roberts74a26a3132e8
diff --git a/app/actions/invite.go b/app/actions/invite.go
index a1645e318..41d5dcee0 100644
--- a/app/actions/invite.go
+++ b/app/actions/invite.go
@@ -20,9 +20,8 @@ type InviteUsers struct {
Subject string `json:"subject"`
Message string `json:"message"`
Recipients []string `json:"recipients" format:"lower"`
- IsSampleInvite bool
-
- Invitations []*UserInvitation
+ IsSampleInvite bool `json:"-"`
+ Invitations []*UserInvitation `json:"-"`
}
// IsAuthorized returns true if current user is authorized to perform this action
diff --git a/app/actions/signin.go b/app/actions/signin.go
index 03927f740..28efb1eac 100644
--- a/app/actions/signin.go
+++ b/app/actions/signin.go
@@ -15,8 +15,8 @@ import (
// SignInByEmail happens when user request to sign in by email
type SignInByEmail struct {
Email string `json:"email" format:"lower"`
- VerificationCode string
- LinkKey string
+ VerificationCode string `json:"-"`
+ LinkKey string `json:"-"`
}
func NewSignInByEmail() *SignInByEmail {
@@ -119,8 +119,8 @@ func (action *VerifySignInCode) Validate(ctx context.Context, user *entity.User)
type SignInByEmailWithName struct {
Email string `json:"email" format:"lower"`
Name string `json:"name"`
- VerificationCode string
- LinkKey string
+ VerificationCode string `json:"-"`
+ LinkKey string `json:"-"`
}
func NewSignInByEmailWithName() *SignInByEmailWithName {
diff --git a/app/actions/signin_test.go b/app/actions/signin_test.go
index d7a5fde39..35b81f772 100644
--- a/app/actions/signin_test.go
+++ b/app/actions/signin_test.go
@@ -2,6 +2,7 @@ package actions_test
import (
"context"
+ "encoding/json"
"testing"
"github.com/getfider/fider/app/actions"
@@ -36,6 +37,42 @@ func TestSignInByEmail_ShouldHaveVerificationKey(t *testing.T) {
Expect(len(action.VerificationCode)).Equals(6)
}
+func TestSignInByEmail_VerificationCodeNotOverwrittenByJSON(t *testing.T) {
+ RegisterT(t)
+
+ action := actions.NewSignInByEmail()
+ originalCode := action.VerificationCode
+ originalKey := action.LinkKey
+
+ // Simulate attacker trying to overwrite internal fields via JSON binding
+ payload := []byte(`{"email":"[email protected]","VerificationCode":"000000","LinkKey":"attacker-key"}`)
+ err := json.Unmarshal(payload, action)
+ Expect(err).IsNil()
+
+ // VerificationCode and LinkKey must NOT be overwritten
+ Expect(action.VerificationCode).Equals(originalCode)
+ Expect(action.LinkKey).Equals(originalKey)
+ // Email should still bind normally
+ Expect(action.Email).Equals("[email protected]")
+}
+
+func TestSignInByEmailWithName_VerificationCodeNotOverwrittenByJSON(t *testing.T) {
+ RegisterT(t)
+
+ action := actions.NewSignInByEmailWithName()
+ originalCode := action.VerificationCode
+ originalKey := action.LinkKey
+
+ payload := []byte(`{"email":"[email protected]","name":"Attacker","VerificationCode":"000000","LinkKey":"attacker-key"}`)
+ err := json.Unmarshal(payload, action)
+ Expect(err).IsNil()
+
+ Expect(action.VerificationCode).Equals(originalCode)
+ Expect(action.LinkKey).Equals(originalKey)
+ Expect(action.Email).Equals("[email protected]")
+ Expect(action.Name).Equals("Attacker")
+}
+
func TestCompleteProfile_EmptyNameAndKey(t *testing.T) {
RegisterT(t)
diff --git a/app/actions/tenant.go b/app/actions/tenant.go
index 26bce8efc..7c957eb1a 100644
--- a/app/actions/tenant.go
+++ b/app/actions/tenant.go
@@ -23,11 +23,11 @@ type CreateTenant struct {
Token string `json:"token"`
Name string `json:"name"`
Email string `json:"email" format:"lower"`
- VerificationKey string
- TenantName string `json:"tenantName"`
- LegalAgreement bool `json:"legalAgreement"`
- Subdomain string `json:"subdomain" format:"lower"`
- UserClaims *jwt.OAuthClaims
+ VerificationKey string `json:"-"`
+ TenantName string `json:"tenantName"`
+ LegalAgreement bool `json:"legalAgreement"`
+ Subdomain string `json:"subdomain" format:"lower"`
+ UserClaims *jwt.OAuthClaims `json:"-"`
}
func NewCreateTenant() *CreateTenant {
@@ -119,7 +119,7 @@ func (action *CreateTenant) GetKind() enum.EmailVerificationKind {
// ResendSignUpEmail is the input model used to resend signup verification email
type ResendSignUpEmail struct {
- VerificationKey string
+ VerificationKey string `json:"-"`
}
func NewResendSignUpEmail() *ResendSignUpEmail {
diff --git a/app/actions/user.go b/app/actions/user.go
index 0d611f3bc..65ad0a0bc 100644
--- a/app/actions/user.go
+++ b/app/actions/user.go
@@ -95,8 +95,8 @@ func (action *ChangeUserRole) Validate(ctx context.Context, user *entity.User) *
//ChangeUserEmail is the action used to change current user's email
type ChangeUserEmail struct {
Email string `json:"email" format:"lower"`
- VerificationKey string
- Requestor *entity.User
+ VerificationKey string `json:"-"`
+ Requestor *entity.User `json:"-"`
}
func NewChangeUserEmail() *ChangeUserEmail {