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

Unified Diff: extensions/renderer/utils_native_handler.cc

Issue 1903303002: Ensure that privates are private. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/renderer/utils_native_handler.cc
diff --git a/extensions/renderer/utils_native_handler.cc b/extensions/renderer/utils_native_handler.cc
index 1ded40c6ad2b0017c86c761782c33c6b8311d086..66fc458e4e068afa50d69d2502c07efd817170f8 100644
--- a/extensions/renderer/utils_native_handler.cc
+++ b/extensions/renderer/utils_native_handler.cc
@@ -4,13 +4,29 @@
#include "extensions/renderer/utils_native_handler.h"
+#include <algorithm>
+
#include "base/macros.h"
+#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "extensions/renderer/script_context.h"
#include "third_party/WebKit/public/web/WebSerializedScriptValue.h"
namespace extensions {
+namespace {
+
+// Returns whether |name| can safely be used as an identifier in JavaScript code
+// without side effects. This method allows syntax errors, but not execution of
+// arbitrary JavaScript code.
+bool IsAllowedFunctionName(const std::string& name) {
+ return std::find_if_not(name.begin(), name.end(), [](char c) {
+ return base::IsAsciiAlpha(c);
+ }) == name.end();
+}
+
+} // namespace
+
UtilsNativeHandler::UtilsNativeHandler(ScriptContext* context)
: ObjectBackedNativeHandler(context) {
RouteFunction("createClassWrapper",
@@ -28,6 +44,7 @@ void UtilsNativeHandler::CreateClassWrapper(
CHECK_EQ(3, args.Length());
CHECK(args[0]->IsString());
std::string name = *v8::String::Utf8Value(args[0]);
+ CHECK(IsAllowedFunctionName(name));
CHECK(args[1]->IsObject());
v8::Local<v8::Object> cls = args[1].As<v8::Object>();
CHECK(args[2]->IsObject() || args[2]->IsUndefined());
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698