@@ -762,60 +762,71 @@ var authorizationValidationMap = map[string]func(ctx context.Context, handler *v
762762 },
763763 "/raystack.frontier.v1beta1.FrontierService/GetBillingAccount" : func (ctx context.Context , handler * v1beta1connect.ConnectHandler , req connect.AnyRequest ) error {
764764 pbreq := req .(* connect.Request [frontierv1beta1.GetBillingAccountRequest ])
765- if err := ensureBillingAccountBelongToOrg (ctx , handler , pbreq .Msg .GetOrgId (), pbreq .Msg .GetId ()); err != nil {
765+ orgID , err := getOrgForBillingAccount (ctx , handler , pbreq .Msg .GetId ())
766+ if err != nil {
766767 return err
767768 }
768- return handler .IsAuthorized (ctx , relation.Object {Namespace : schema .OrganizationNamespace , ID : pbreq . Msg . GetOrgId () }, schema .GetPermission , req )
769+ return handler .IsAuthorized (ctx , relation.Object {Namespace : schema .OrganizationNamespace , ID : orgID }, schema .GetPermission , req )
769770 },
770771 "/raystack.frontier.v1beta1.FrontierService/GetBillingBalance" : func (ctx context.Context , handler * v1beta1connect.ConnectHandler , req connect.AnyRequest ) error {
771772 pbreq := req .(* connect.Request [frontierv1beta1.GetBillingBalanceRequest ])
772- if err := ensureBillingAccountBelongToOrg (ctx , handler , pbreq .Msg .GetOrgId (), pbreq .Msg .GetId ()); err != nil {
773+ orgID , err := getOrgForBillingAccount (ctx , handler , pbreq .Msg .GetId ())
774+ if err != nil {
773775 return err
774776 }
775- return handler .IsAuthorized (ctx , relation.Object {Namespace : schema .OrganizationNamespace , ID : pbreq . Msg . GetOrgId () }, schema .GetPermission , req )
777+ return handler .IsAuthorized (ctx , relation.Object {Namespace : schema .OrganizationNamespace , ID : orgID }, schema .GetPermission , req )
776778 },
777779 "/raystack.frontier.v1beta1.FrontierService/CheckCreditEntitlement" : func (ctx context.Context , handler * v1beta1connect.ConnectHandler , req connect.AnyRequest ) error {
778780 pbreq := req .(* connect.Request [frontierv1beta1.CheckCreditEntitlementRequest ])
779781 return handler .IsAuthorized (ctx , relation.Object {Namespace : schema .OrganizationNamespace , ID : pbreq .Msg .GetOrgId ()}, schema .GetPermission , req )
780782 },
781783 "/raystack.frontier.v1beta1.FrontierService/UpdateBillingAccount" : func (ctx context.Context , handler * v1beta1connect.ConnectHandler , req connect.AnyRequest ) error {
782784 pbreq := req .(* connect.Request [frontierv1beta1.UpdateBillingAccountRequest ])
783- if err := ensureBillingAccountBelongToOrg (ctx , handler , pbreq .Msg .GetOrgId (), pbreq .Msg .GetId ()); err != nil {
785+ orgID , err := getOrgForBillingAccount (ctx , handler , pbreq .Msg .GetId ())
786+ if err != nil {
784787 return err
785788 }
786- return handler .IsAuthorized (ctx , relation.Object {Namespace : schema .OrganizationNamespace , ID : pbreq . Msg . GetOrgId () }, schema .DeletePermission , req )
789+ return handler .IsAuthorized (ctx , relation.Object {Namespace : schema .OrganizationNamespace , ID : orgID }, schema .DeletePermission , req )
787790 },
788791 "/raystack.frontier.v1beta1.FrontierService/DeleteBillingAccount" : func (ctx context.Context , handler * v1beta1connect.ConnectHandler , req connect.AnyRequest ) error {
789792 pbreq := req .(* connect.Request [frontierv1beta1.DeleteBillingAccountRequest ])
790- if err := ensureBillingAccountBelongToOrg (ctx , handler , pbreq .Msg .GetOrgId (), pbreq .Msg .GetId ()); err != nil {
793+ orgID , err := getOrgForBillingAccount (ctx , handler , pbreq .Msg .GetId ())
794+ if err != nil {
791795 return err
792796 }
793- return handler .IsAuthorized (ctx , relation.Object {Namespace : schema .OrganizationNamespace , ID : pbreq . Msg . GetOrgId () }, schema .DeletePermission , req )
797+ return handler .IsAuthorized (ctx , relation.Object {Namespace : schema .OrganizationNamespace , ID : orgID }, schema .DeletePermission , req )
794798 },
795799 "/raystack.frontier.v1beta1.FrontierService/EnableBillingAccount" : func (ctx context.Context , handler * v1beta1connect.ConnectHandler , req connect.AnyRequest ) error {
796800 pbreq := req .(* connect.Request [frontierv1beta1.EnableBillingAccountRequest ])
797- if err := ensureBillingAccountBelongToOrg (ctx , handler , pbreq .Msg .GetOrgId (), pbreq .Msg .GetId ()); err != nil {
801+ orgID , err := getOrgForBillingAccount (ctx , handler , pbreq .Msg .GetId ())
802+ if err != nil {
798803 return err
799804 }
800- return handler .IsAuthorized (ctx , relation.Object {Namespace : schema .OrganizationNamespace , ID : pbreq . Msg . GetOrgId () }, schema .DeletePermission , req )
805+ return handler .IsAuthorized (ctx , relation.Object {Namespace : schema .OrganizationNamespace , ID : orgID }, schema .DeletePermission , req )
801806 },
802807 "/raystack.frontier.v1beta1.FrontierService/DisableBillingAccount" : func (ctx context.Context , handler * v1beta1connect.ConnectHandler , req connect.AnyRequest ) error {
803808 pbreq := req .(* connect.Request [frontierv1beta1.DisableBillingAccountRequest ])
804- if err := ensureBillingAccountBelongToOrg (ctx , handler , pbreq .Msg .GetOrgId (), pbreq .Msg .GetId ()); err != nil {
809+ orgID , err := getOrgForBillingAccount (ctx , handler , pbreq .Msg .GetId ())
810+ if err != nil {
805811 return err
806812 }
807- return handler .IsAuthorized (ctx , relation.Object {Namespace : schema .OrganizationNamespace , ID : pbreq . Msg . GetOrgId () }, schema .DeletePermission , req )
813+ return handler .IsAuthorized (ctx , relation.Object {Namespace : schema .OrganizationNamespace , ID : orgID }, schema .DeletePermission , req )
808814 },
809815 "/raystack.frontier.v1beta1.FrontierService/HasTrialed" : func (ctx context.Context , handler * v1beta1connect.ConnectHandler , req connect.AnyRequest ) error {
810816 pbreq := req .(* connect.Request [frontierv1beta1.HasTrialedRequest ])
811- if err := ensureBillingAccountBelongToOrg (ctx , handler , pbreq .Msg .GetOrgId (), pbreq .Msg .GetId ()); err != nil {
817+ orgID , err := getOrgForBillingAccount (ctx , handler , pbreq .Msg .GetId ())
818+ if err != nil {
812819 return err
813820 }
814- return handler .IsAuthorized (ctx , relation.Object {Namespace : schema .OrganizationNamespace , ID : pbreq . Msg . GetOrgId () }, schema .GetPermission , req )
821+ return handler .IsAuthorized (ctx , relation.Object {Namespace : schema .OrganizationNamespace , ID : orgID }, schema .GetPermission , req )
815822 },
816823 "/raystack.frontier.v1beta1.FrontierService/RegisterBillingAccount" : func (ctx context.Context , handler * v1beta1connect.ConnectHandler , req connect.AnyRequest ) error {
817824 pbreq := req .(* connect.Request [frontierv1beta1.RegisterBillingAccountRequest ])
818- return handler .IsAuthorized (ctx , relation.Object {Namespace : schema .OrganizationNamespace , ID : pbreq .Msg .GetOrgId ()}, schema .DeletePermission , req )
825+ orgID , err := getOrgForBillingAccount (ctx , handler , pbreq .Msg .GetId ())
826+ if err != nil {
827+ return err
828+ }
829+ return handler .IsAuthorized (ctx , relation.Object {Namespace : schema .OrganizationNamespace , ID : orgID }, schema .DeletePermission , req )
819830 },
820831
821832 // subscriptions - org_id and billing_id are now inferred from subscription_id
@@ -1052,14 +1063,16 @@ var authorizationValidationMap = map[string]func(ctx context.Context, handler *v
10521063 },
10531064 "/raystack.frontier.v1beta1.AdminService/GetBillingAccountDetails" : func (ctx context.Context , handler * v1beta1connect.ConnectHandler , req connect.AnyRequest ) error {
10541065 pbReq := req .(* connect.Request [frontierv1beta1.GetBillingAccountDetailsRequest ])
1055- if err := ensureBillingAccountBelongToOrg (ctx , handler , pbReq .Msg .GetOrgId (), pbReq .Msg .GetId ()); err != nil {
1066+ _ , err := getOrgForBillingAccount (ctx , handler , pbReq .Msg .GetId ())
1067+ if err != nil {
10561068 return err
10571069 }
10581070 return handler .IsSuperUser (ctx , req )
10591071 },
10601072 "/raystack.frontier.v1beta1.AdminService/UpdateBillingAccountDetails" : func (ctx context.Context , handler * v1beta1connect.ConnectHandler , req connect.AnyRequest ) error {
10611073 pbReq := req .(* connect.Request [frontierv1beta1.UpdateBillingAccountDetailsRequest ])
1062- if err := ensureBillingAccountBelongToOrg (ctx , handler , pbReq .Msg .GetOrgId (), pbReq .Msg .GetId ()); err != nil {
1074+ _ , err := getOrgForBillingAccount (ctx , handler , pbReq .Msg .GetId ())
1075+ if err != nil {
10631076 return err
10641077 }
10651078 return handler .IsSuperUser (ctx , req )
@@ -1122,18 +1135,14 @@ func ensureRoleBelongToOrg(ctx context.Context, handler *v1beta1connect.ConnectH
11221135 return nil
11231136}
11241137
1125- func ensureBillingAccountBelongToOrg (ctx context.Context , handler * v1beta1connect.ConnectHandler , orgID , billingID string ) error {
1126- acc , err := handler .GetBillingAccount (ctx , connect .NewRequest (& frontierv1beta1.GetBillingAccountRequest {
1127- OrgId : orgID ,
1128- Id : billingID ,
1129- }))
1138+ func getOrgForBillingAccount (ctx context.Context , handler * v1beta1connect.ConnectHandler , billingID string ) (string , error ) {
1139+ // Infer org_id from billing_id (don't trust org_id from request for security)
1140+ orgID , err := handler .GetOrgIDFromBillingAccountID (ctx , billingID )
11301141 if err != nil {
1131- return err
1132- }
1133- if acc .Msg .GetBillingAccount ().GetOrgId () != orgID {
1134- return ErrDeniedInvalidArgs
1142+ return "" , err
11351143 }
1136- return nil
1144+ // Return the inferred org_id for authorization check
1145+ return orgID , nil
11371146}
11381147
11391148func ensureSubscriptionBelongToOrg (ctx context.Context , handler * v1beta1connect.ConnectHandler , subID string ) (string , error ) {
0 commit comments