Skip to content

Commit 4b7019d

Browse files
authored
Merge pull request #4355 from 3scale/THREESCALE-11522-fix-validate-readonly-fields
THREESCALE-11522: Backport fix for CVE-2024-12125 [2.15]
2 parents ed382b5 + 8fafea4 commit 4b7019d

14 files changed

Lines changed: 143 additions & 7 deletions

File tree

app/models/fields_definition.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def self.push_target(klass)
2424
scope :by_target, ->(class_name) { where(['target = ?', class_name])}
2525
scope :by_name, ->(name) { where(['name = ?', name])}
2626
scope :required, -> { where({ :required => true })}
27+
scope :read_only, ->(read_only = true) { where(read_only: read_only) }
2728

2829
def self.editable_by(user)
2930
select{ |fd| fd.editable_by?(user) }

features/developer_portal/admin/applications/extra_fields.feature

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,28 @@ Feature: Developer portal application extra fields
6363
| Plate number |
6464
| Stealth |
6565

66+
Scenario: Read-only extra fields are ignored if received
67+
Given the following application:
68+
| Buyer | Name | Product |
69+
| Jane | Jane's App | The API |
70+
And the application has the following extra fields:
71+
| Description | It's a car |
72+
| Engine | 120 |
73+
| Wheels | 4 |
74+
| Color | White |
75+
When the buyer logs in
76+
And the provider has the field "plate_number" for applications as editable
77+
And they go to application "Jane's App" dev portal edit page
78+
And the provider has the field "plate_number" for applications as read only
79+
And the form is submitted with:
80+
| Description | It's a car |
81+
| Engine | 120 |
82+
| Wheels | 4 |
83+
| Color | White |
84+
| Plate number | edit me |
85+
Then they should see the flash message "Application was successfully updated"
86+
And they should not see "Plate number"
87+
6688
Scenario: Extra fields validation
6789
When they go to the dev portal new application page
6890
And the form is submitted with:

features/old/accounts/buyers/account_fields.feature

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ Feature: Buyer side, account fields
4646
And I press "Update"
4747
Then I should see "The account information was updated."
4848

49+
Scenario: Read-only extra fields are ignored on update
50+
Given I log in as "bob" on foo.3scale.localhost
51+
And provider "foo.3scale.localhost" has the field "non_editable" for accounts as editable
52+
Then I go to the account edit page
53+
And provider "foo.3scale.localhost" has the field "non_editable" for accounts as read only
54+
And the form is submitted with:
55+
| Required field | value |
56+
| False field | |
57+
| Choices field | 3 |
58+
| Non editable | edited |
59+
Then I should see "The account information was updated."
60+
Then I should not see "Non editable"
4961

5062
Scenario: Viewing account with extra fields
5163
#TODO ugly table change this

features/step_definitions/provider_steps.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ def import_simple_layout(provider)
6161
a.save!
6262
end
6363

64+
Given "{provider} has the field {string} for {field_definition_target} as {read_only_status}" do |provider, name, target, read_only|
65+
a = provider.fields_definitions.by_target(target).find { |fd| fd.name == name }
66+
a.read_only = read_only
67+
a.save!
68+
end
69+
6470
Given "{provider} allows to change account plan {change_plan_permission}" do |provider, plan_permission|
6571
provider.set_change_account_plan_permission! plan_permission
6672
end

features/support/parameter_types.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,3 +469,14 @@ def find_metric(metrics, name)
469469
regexp: /(.*)/,
470470
transformer: ->(selector) { selector_for(selector) }
471471
)
472+
473+
ParameterType(
474+
name: 'read_only_status',
475+
regexp: /(editable|read only)/,
476+
transformer: ->(value) do
477+
{
478+
'editable' => false,
479+
'read only' => true,
480+
}[value]
481+
end
482+
)

lib/developer_portal/app/controllers/developer_portal/accounts/invitee_signups_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def check_invitation!
119119
end
120120

121121
def build_user
122-
@user = @invitation.make_user(params[:user] || {})
122+
@user = @invitation.make_user(filter_readonly_params(params[:user], User))
123123
end
124124

125125
def invitation_token

lib/developer_portal/app/controllers/developer_portal/admin/account/personal_details_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def deny_unless_can_update
4646
end
4747

4848
def user_params
49-
params.require(:user).permit([:current_password] +
49+
filter_readonly_params(params.require(:user), User).permit([:current_password] +
5050
resource.special_fields +
5151
resource.defined_fields.map(&:name))
5252
end

lib/developer_portal/app/controllers/developer_portal/admin/account/users_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def collection
5353

5454
def update_resource(user, attributes)
5555
attributes.each do |attrs|
56-
user.attributes = attrs
56+
user.attributes = filter_readonly_params(attrs, User)
5757
user.role = attrs[:role] if can? :update_role, user
5858
end
5959
user.save

lib/developer_portal/app/controllers/developer_portal/admin/accounts_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def update
3535
private
3636

3737
def account_params
38-
params.require(:account)
38+
filter_readonly_params(params.require(:account), Account)
3939
end
4040

4141
def find_countries

lib/developer_portal/app/controllers/developer_portal/admin/applications_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,12 @@ def accepted_application_params
172172
# cinstance[*] naming is present for legacy reasons
173173
application_attributes = params[:application] || params[:cinstance]
174174
return {} unless application_attributes
175+
175176
permitted_params = fields_definitions + %i[plan_id redirect_url]
176177
application_attributes.permit(*permitted_params)
177178
end
178179

179180
def fields_definitions
180-
FieldsDefinition.by_provider(site_account).by_target('Cinstance').pluck(:name)
181+
FieldsDefinition.by_provider(site_account).by_target('Cinstance').read_only(false).pluck(:name)
181182
end
182183
end

0 commit comments

Comments
 (0)