mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Better error handling for invalid locale bundle versions
This commit is contained in:
parent
34665d3f96
commit
6ebffaaf6e
@ -9,15 +9,20 @@ class ExtraLocalesController < ApplicationController
|
|||||||
:verify_authenticity_token
|
:verify_authenticity_token
|
||||||
|
|
||||||
OVERRIDES_BUNDLE ||= 'overrides'
|
OVERRIDES_BUNDLE ||= 'overrides'
|
||||||
|
MD5_HASH_LENGTH ||= 32
|
||||||
|
|
||||||
def show
|
def show
|
||||||
bundle = params[:bundle]
|
bundle = params[:bundle]
|
||||||
|
|
||||||
raise Discourse::InvalidAccess.new if !valid_bundle?(bundle)
|
raise Discourse::InvalidAccess.new if !valid_bundle?(bundle)
|
||||||
|
|
||||||
if params[:v]&.size == 32
|
version = params[:v]
|
||||||
hash = ExtraLocalesController.bundle_js_hash(bundle)
|
if version.present?
|
||||||
immutable_for(1.year) if hash == params[:v]
|
if version.kind_of?(String) && version.length == MD5_HASH_LENGTH
|
||||||
|
hash = ExtraLocalesController.bundle_js_hash(bundle)
|
||||||
|
immutable_for(1.year) if hash == version
|
||||||
|
else
|
||||||
|
raise Discourse::InvalidParameters.new(:v)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
render plain: ExtraLocalesController.bundle_js(bundle), content_type: "application/javascript"
|
render plain: ExtraLocalesController.bundle_js(bundle), content_type: "application/javascript"
|
||||||
|
@ -23,6 +23,14 @@ describe ExtraLocalesController do
|
|||||||
expect(response.status).to eq(403)
|
expect(response.status).to eq(403)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "requires a valid version" do
|
||||||
|
get "/extra-locales/overrides", params: { v: 'a' }
|
||||||
|
expect(response.status).to eq(400)
|
||||||
|
|
||||||
|
get "/extra-locales/overrides?v[foo]=1"
|
||||||
|
expect(response.status).to eq(400)
|
||||||
|
end
|
||||||
|
|
||||||
context "logged in as a moderator" do
|
context "logged in as a moderator" do
|
||||||
|
|
||||||
let(:moderator) { Fabricate(:moderator) }
|
let(:moderator) { Fabricate(:moderator) }
|
||||||
|
Loading…
Reference in New Issue
Block a user