add-flag-to-force-punycode-hostnames.patch 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # Add flag to force punycode in hostnames instead of Unicode when displaying Internationalized Domain Names (IDNs) to mitigate homograph attacks
  2. --- a/chrome/browser/about_flags.cc
  3. +++ b/chrome/browser/about_flags.cc
  4. @@ -1215,6 +1215,10 @@ const FeatureEntry kFeatureEntries[] = {
  5. "Disable search engine collection",
  6. "Prevents search engines from being added automatically.",
  7. kOsAll, SINGLE_VALUE_TYPE("disable-search-engine-collection")},
  8. + {"force-punycode-hostnames",
  9. + "Force punycode hostnames",
  10. + "Force punycode in hostnames instead of Unicode when displaying Internationalized Domain Names (IDNs).",
  11. + kOsAll, SINGLE_VALUE_TYPE("force-punycode-hostnames")},
  12. {"ignore-gpu-blacklist", flag_descriptions::kIgnoreGpuBlacklistName,
  13. flag_descriptions::kIgnoreGpuBlacklistDescription, kOsAll,
  14. SINGLE_VALUE_TYPE(switches::kIgnoreGpuBlacklist)},
  15. --- a/components/url_formatter/url_formatter.cc
  16. +++ b/components/url_formatter/url_formatter.cc
  17. @@ -8,6 +8,7 @@
  18. #include <utility>
  19. #include <vector>
  20. +#include "base/command_line.h"
  21. #include "base/lazy_instance.h"
  22. #include "base/numerics/safe_conversions.h"
  23. #include "base/stl_util.h"
  24. @@ -245,6 +246,13 @@ IDNConversionResult IDNToUnicodeWithAdju
  25. input16.reserve(host.length());
  26. input16.insert(input16.end(), host.begin(), host.end());
  27. + if (base::CommandLine::ForCurrentProcess()->HasSwitch("force-punycode-hostnames")) {
  28. + // Leave as punycode.
  29. + IDNConversionResult result;
  30. + result.result = input16;
  31. + return result;
  32. + }
  33. +
  34. bool is_tld_ascii = true;
  35. size_t last_dot = host.rfind('.');
  36. if (last_dot != base::StringPiece::npos &&