Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Unified Diff: components/url_formatter/idn_spoof_checker.h

Issue 2877973003: Pull out IDN_Spoof_Checker to separate cc/h files. (Closed)
Patch Set: fix a typo in regex Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/url_formatter/BUILD.gn ('k') | components/url_formatter/idn_spoof_checker.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/url_formatter/idn_spoof_checker.h
diff --git a/components/url_formatter/idn_spoof_checker.h b/components/url_formatter/idn_spoof_checker.h
new file mode 100644
index 0000000000000000000000000000000000000000..41eafc637b1ce2847df644f26768fbbfa687b20a
--- /dev/null
+++ b/components/url_formatter/idn_spoof_checker.h
@@ -0,0 +1,63 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_URL_FORMATTER_IDN_SPOOF_CHECKER_H_
+#define COMPONENTS_URL_FORMATTER_IDN_SPOOF_CHECKER_H_
+
+#include <memory>
+#include <string>
+
+#include "base/strings/string16.h"
+#include "base/strings/string_piece.h"
+#include "third_party/icu/source/common/unicode/uniset.h"
+#include "third_party/icu/source/common/unicode/utypes.h"
+#include "third_party/icu/source/common/unicode/uversion.h"
+
+// 'icu' does not work. Use U_ICU_NAMESPACE.
+namespace U_ICU_NAMESPACE {
+
+class UnicodeString;
+
+} // namespace U_ICU_NAMESPACE
+
+struct USpoofChecker;
+
+namespace url_formatter {
+
+// A helper class for IDN Spoof checking, used to ensure that no IDN input is
+// spoofable per Chromium's standard of spoofability. For a more thorough
+// explanation of how spoof checking works in Chromium, see
+// http://dev.chromium.org/developers/design-documents/idn-in-google-chrome .
+
+class IDNSpoofChecker {
+ public:
+ IDNSpoofChecker();
+ ~IDNSpoofChecker();
+
+ // Returns true if |label| is safe to display as Unicode. In the event of
+ // library failure, all IDN inputs will be treated as unsafe.
+ // See the function body for details on the specific safety checks performed.
+ bool SafeToDisplayAsUnicode(base::StringPiece16 label, bool is_tld_ascii);
+
+ private:
+ // Sets allowed characters in IDN labels and turns on USPOOF_CHAR_LIMIT.
+ void SetAllowedUnicodeSet(UErrorCode* status);
+ // Returns true if all the Cyrillic letters in |label| belong to a set of
+ // Cyrillic letters that look like ASCII Latin letters.
+ bool IsMadeOfLatinAlikeCyrillic(const icu::UnicodeString& label);
+
+ USpoofChecker* checker_;
+ icu::UnicodeSet deviation_characters_;
+ icu::UnicodeSet non_ascii_latin_letters_;
+ icu::UnicodeSet kana_letters_exceptions_;
+ icu::UnicodeSet cyrillic_letters_;
+ icu::UnicodeSet cyrillic_letters_latin_alike_;
+
+ IDNSpoofChecker(const IDNSpoofChecker&) = delete;
+ void operator=(const IDNSpoofChecker&) = delete;
+};
+
+} // namespace url_formatter
+
+#endif // COMPONENTS_URL_FORMATTER_IDN_SPOOF_CHECKER_H_
« no previous file with comments | « components/url_formatter/BUILD.gn ('k') | components/url_formatter/idn_spoof_checker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698