Skip to content

Conversation

@adamsaimi
Copy link
Owner

Test 9

The FallbackLocaleList object tells I18n::Backend::Fallbacks what order the
languages should be attempted in. Because of the translate_accelerator patch,
the SiteSetting.default_locale is *not* guaranteed to be fully loaded after the
server starts, so a call to ensure_loaded! is added after the locale is set for
the current user.

The declarations of config.i18n.fallbacks = true in the environment files were
actually garbage, because the I18n.default_locale was
SiteSetting.default_locale, so there was nothing to fall back to. *derp*
# user locale, site locale, english
# TODO - this can be extended to be per-language for a better user experience
# (e.g. fallback zh_TW to zh_CN / vice versa)
[locale, SiteSetting.default_locale.to_sym, :en].uniq.compact
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Security] Path Traversal in I18n.locale

  • Problem: User-controlled I18n.locale is used in locale loading without sanitization, risking arbitrary file reads via path traversal.
  • Fix: Strictly validate and sanitize I18n.locale to allow only valid identifiers, preventing path traversal attacks.

end
end

def ensure_loaded!(locale)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Refactor] Intrusive Monkey-Patching of I18n Backend

  • Problem: The ensure_loaded! method is added to I18n::Backend::Simple via a freedom patch, leading to fragility and potential conflicts.
  • Fix: Re-evaluate the need for monkey-patching; consider alternative, less intrusive ways to extend I18n functionality or encapsulate the behavior.

# user locale, site locale, english
# TODO - this can be extended to be per-language for a better user experience
# (e.g. fallback zh_TW to zh_CN / vice versa)
[locale, SiteSetting.default_locale.to_sym, :en].uniq.compact
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Refactor] Tight Coupling in I18n Fallback Logic

  • Problem: The FallbackLocaleList directly accesses SiteSetting.default_locale, tightly coupling the I18n fallback mechanism to a specific application configuration.
  • Fix: Decouple FallbackLocaleList from SiteSetting.default_locale by injecting the default locale or using a more generic configuration access pattern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants