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

Side by Side Diff: chrome/browser/ui/webui/extensions/extension_error_handler.cc

Issue 23875013: Handle invalid input for SourceHighlighter, Don't Allow Relative Paths in ErrorHandler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove comment + address security risk in ErrorHandler Created 7 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | extensions/browser/file_highlighter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/extensions/extension_error_handler.h" 5 #include "chrome/browser/ui/webui/extensions/extension_error_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 const base::ListValue* args) { 83 const base::ListValue* args) {
84 // There should only be one argument, a dictionary. Use this instead of a list 84 // There should only be one argument, a dictionary. Use this instead of a list
85 // because it's more descriptive, harder to accidentally break with minor 85 // because it's more descriptive, harder to accidentally break with minor
86 // modifications, and supports optional arguments more easily. 86 // modifications, and supports optional arguments more easily.
87 CHECK_EQ(1u, args->GetSize()); 87 CHECK_EQ(1u, args->GetSize());
88 88
89 const base::DictionaryValue* dict = NULL; 89 const base::DictionaryValue* dict = NULL;
90 90
91 // Three required arguments: extension_id, path_suffix, and error_message. 91 // Three required arguments: extension_id, path_suffix, and error_message.
92 std::string extension_id; 92 std::string extension_id;
93 base::FilePath::StringType path_suffix; 93 base::FilePath::StringType path_suffix_string;
94 base::string16 error_message; 94 base::string16 error_message;
95 95
96 if (!args->GetDictionary(0, &dict) || 96 if (!args->GetDictionary(0, &dict) ||
97 !dict->GetString(kPathSuffixKey, &path_suffix) || 97 !dict->GetString(kPathSuffixKey, &path_suffix_string) ||
98 !dict->GetString(ExtensionError::kExtensionIdKey, &extension_id) || 98 !dict->GetString(ExtensionError::kExtensionIdKey, &extension_id) ||
99 !dict->GetString(ExtensionError::kMessageKey, &error_message)) { 99 !dict->GetString(ExtensionError::kMessageKey, &error_message)) {
100 NOTREACHED(); 100 NOTREACHED();
101 return; 101 return;
102 } 102 }
103 103
104 const Extension* extension = 104 const Extension* extension =
105 ExtensionSystem::Get(Profile::FromWebUI(web_ui()))-> 105 ExtensionSystem::Get(Profile::FromWebUI(web_ui()))->
106 extension_service()->GetExtensionById(extension_id, 106 extension_service()->GetExtensionById(extension_id,
107 true /* include disabled */ ); 107 true /* include disabled */ );
108
109 // Under no circumstances should we ever need to reference a file outside of
110 // the extension's directory. If it tries to, abort.
111 base::FilePath path_suffix(path_suffix_string);
112 if (path_suffix.ReferencesParent())
113 return;
114
108 base::FilePath path = extension->path().Append(path_suffix); 115 base::FilePath path = extension->path().Append(path_suffix);
109 116
110 // Setting the title and the error message is the same for all file types. 117 // Setting the title and the error message is the same for all file types.
111 scoped_ptr<base::DictionaryValue> results(new base::DictionaryValue); 118 scoped_ptr<base::DictionaryValue> results(new base::DictionaryValue);
112 results->SetString(kTitleKey, 119 results->SetString(kTitleKey,
113 base::UTF8ToUTF16(extension->name()) + 120 base::UTF8ToUTF16(extension->name()) +
114 base::ASCIIToUTF16(": ") + 121 base::ASCIIToUTF16(": ") +
115 path.BaseName().LossyDisplayName()); 122 path.BaseName().LossyDisplayName());
116 results->SetString(ExtensionError::kMessageKey, error_message); 123 results->SetString(ExtensionError::kMessageKey, error_message);
117 124
118 base::Closure closure; 125 base::Closure closure;
119 std::string* contents = NULL; 126 std::string* contents = NULL;
120 127
121 if (path_suffix == kManifestFilename) { 128 if (path_suffix_string == kManifestFilename) {
122 std::string manifest_key; 129 std::string manifest_key;
123 if (!dict->GetString(ManifestError::kManifestKeyKey, &manifest_key)) { 130 if (!dict->GetString(ManifestError::kManifestKeyKey, &manifest_key)) {
124 NOTREACHED(); 131 NOTREACHED();
125 return; 132 return;
126 } 133 }
127 134
128 // A "specific" location is optional. 135 // A "specific" location is optional.
129 std::string specific; 136 std::string specific;
130 dict->GetString(ManifestError::kManifestSpecificKey, &specific); 137 dict->GetString(ManifestError::kManifestSpecificKey, &specific);
131 138
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 base::DictionaryValue* results, 178 base::DictionaryValue* results,
172 int line_number, 179 int line_number,
173 std::string* contents) { 180 std::string* contents) {
174 SourceHighlighter highlighter(*contents, line_number); 181 SourceHighlighter highlighter(*contents, line_number);
175 highlighter.SetHighlightedRegions(results); 182 highlighter.SetHighlightedRegions(results);
176 web_ui()->CallJavascriptFunction( 183 web_ui()->CallJavascriptFunction(
177 "extensions.ExtensionErrorOverlay.requestFileSourceResponse", *results); 184 "extensions.ExtensionErrorOverlay.requestFileSourceResponse", *results);
178 } 185 }
179 186
180 } // namespace extensions 187 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | extensions/browser/file_highlighter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698