1 Star 0 Fork 22

zouzhimin/rubygem-actionpack

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
CVE-2024-26143.patch 1.84 KB
一键复制 编辑 原始数据 按行查看 历史
From 4c83b331092a79d58e4adffe4be5f250fa5782cc Mon Sep 17 00:00:00 2001
From: ooooooo_q <ooooooo-q@users.noreply.github.com>
Date: Fri, 5 Jan 2024 12:00:02 +0900
Subject: [PATCH] fix XSS vulnerability when using translation
[CVE-2024-26143]
---
actionpack/CHANGELOG.md | 4 +++
.../lib/abstract_controller/translation.rb | 24 +++++++++++++-
actionpack/test/abstract/translation_test.rb | 31 +++++++++++++++++++
3 files changed, 58 insertions(+), 1 deletion(-)
diff --git a/actionpack/lib/abstract_controller/translation.rb b/actionpack/lib/abstract_controller/translation.rb
index db71c172abd6c..bdd44c6893aa2 100644
--- a/actionpack/lib/abstract_controller/translation.rb
+++ b/actionpack/lib/abstract_controller/translation.rb
@@ -25,7 +25,25 @@ def translate(key, **options)
i18n_raise = options.fetch(:raise, self.raise_on_missing_translations)
- ActiveSupport::HtmlSafeTranslation.translate(key, **options, raise: i18n_raise)
+ if options[:default]
+ options[:default] = [options[:default]] unless options[:default].is_a?(Array)
+ options[:default] = options[:default].map do |value|
+ value.is_a?(String) ? ERB::Util.html_escape(value) : value
+ end
+ end
+
+ unless i18n_raise
+ options[:default] = [] unless options[:default]
+ options[:default] << MISSING_TRANSLATION
+ end
+
+ result = ActiveSupport::HtmlSafeTranslation.translate(key, **options, raise: i18n_raise)
+
+ if result == MISSING_TRANSLATION
+ +"translation missing: #{key}"
+ else
+ result
+ end
end
alias :t :translate
@@ -34,5 +52,9 @@ def localize(object, **options)
I18n.localize(object, **options)
end
alias :l :localize
+
+ private
+ MISSING_TRANSLATION = -(2**60)
+ private_constant :MISSING_TRANSLATION
end
end
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/xiangbudaomz/rubygem-actionpack.git
git@gitee.com:xiangbudaomz/rubygem-actionpack.git
xiangbudaomz
rubygem-actionpack
rubygem-actionpack
master

搜索帮助