Do not allow staff_user_id to be mutated (#6009) [deploy]

Allowing ids to be mutated by admins from the /internal/config pages is dangerous.
This could cause issues if an admin tries to update the SiteConfig.staff_user_id to an id that is another user's id, or to an id that isn't valid.
This commit is contained in:
Vaidehi Joshi 2020-02-10 16:35:18 -08:00 committed by GitHub
parent b9b6281ec3
commit c33d6936b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 13 deletions

View file

@ -18,7 +18,7 @@ class Internal::ConfigsController < Internal::ApplicationController
def config_params
allowed_params = %i[
staff_user_id default_site_email social_networks_handle
default_site_email social_networks_handle
main_social_image favicon_url logo_svg
rate_limit_follow_count_daily
ga_view_id ga_fetch_rate

View file

@ -12,16 +12,6 @@
<div class="card mt-3">
<div class="card-header">Staff</div>
<div class="card-body">
<div class="form-group">
<%= f.label :staff_user_id %>
<%= f.number_field :staff_user_id,
class: "form-control",
value: SiteConfig.staff_user_id,
min: 1,
placeholder: "1" %>
<div class="alert alert-info">User ID of the staff account</div>
</div>
<div class="form-group">
<%= f.label :default_site_email %>
<%= f.email_field :default_site_email,

View file

@ -20,9 +20,10 @@ RSpec.describe "/internal/config", type: :request do
end
describe "staff" do
it "updates staff_user_id" do
it "does not allow the staff_user_id to be updated" do
expect(SiteConfig.staff_user_id).to eq(1)
post "/internal/config", params: { site_config: { staff_user_id: 2 } }
expect(SiteConfig.staff_user_id).to eq(2)
expect(SiteConfig.staff_user_id).to eq(1)
end
it "updates default_site_email" do