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

Side by Side Diff: chrome/browser/notifications/notification_platform_bridge_mac.mm

Issue 2105863002: Verify that the notification response contains sensible data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add upstream branch Created 4 years, 5 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/notifications/notification_platform_bridge_mac.h" 5 #include "chrome/browser/notifications/notification_platform_bridge_mac.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/mac/foundation_util.h" 9 #include "base/mac/foundation_util.h"
10 #include "base/mac/mac_util.h" 10 #include "base/mac/mac_util.h"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 objectForKey:notification_constants::kNotificationId])); 177 objectForKey:notification_constants::kNotificationId]));
178 } 178 }
179 } 179 }
180 return true; 180 return true;
181 } 181 }
182 182
183 bool NotificationPlatformBridgeMac::SupportsNotificationCenter() const { 183 bool NotificationPlatformBridgeMac::SupportsNotificationCenter() const {
184 return true; 184 return true;
185 } 185 }
186 186
187 // static
188 bool NotificationPlatformBridgeMac::VerifyNotificationData(
189 NSDictionary* response) {
190 NSNumber* buttonIndex =
191 [response objectForKey:notification_constants::kNotificationButtonIndex];
192 NSNumber* operation =
193 [response objectForKey:notification_constants::kNotificationOperation];
194
195 std::string notificationOrigin = base::SysNSStringToUTF8(
Peter Beverloo 2016/06/28 23:35:52 unused?
Miguel Garcia 2016/06/30 10:42:00 Done.
196 [response objectForKey:notification_constants::kNotificationOrigin]);
197 NSString* notificationId =
198 [response objectForKey:notification_constants::kNotificationId];
199 NSString* profileId =
200 [response objectForKey:notification_constants::kNotificationProfileId];
201
202 if (buttonIndex.intValue < -1 ||
Peter Beverloo 2016/06/28 23:35:52 I think we're missing `nil` protection here and on
Miguel Garcia 2016/06/30 10:42:00 Yeah I think the right way to do it is ensure that
203 buttonIndex.intValue >=
204 static_cast<int>(blink::kWebNotificationMaxActions)) {
205 LOG(ERROR) << "Invalid number of buttons supplied " << buttonIndex.intValue;
206 return false;
207 }
208
209 if (operation.unsignedIntValue >
210 notification_operation_common::NOTIFICATION_OPERATION_MAX) {
211 LOG(ERROR) << operation.unsignedIntValue
212 << " Does not correspond to a valid operation.";
Peter Beverloo 2016/06/28 23:35:52 nit: Does -> does
Miguel Garcia 2016/06/30 10:42:00 Done.
213 return false;
214 }
215
216 if (notificationId.length <= 0) {
217 LOG(ERROR) << "NotificationId not provided";
218 return false;
219 }
220
221 if (profileId.length <= 0) {
222 LOG(ERROR) << "ProfileId not provided";
223 return false;
224 }
225
226 return true;
227 }
228
187 // ///////////////////////////////////////////////////////////////////////////// 229 // /////////////////////////////////////////////////////////////////////////////
188 230
189 @implementation NotificationCenterDelegate 231 @implementation NotificationCenterDelegate
190 - (void)userNotificationCenter:(NSUserNotificationCenter*)center 232 - (void)userNotificationCenter:(NSUserNotificationCenter*)center
191 didActivateNotification:(NSUserNotification*)notification { 233 didActivateNotification:(NSUserNotification*)notification {
192 NSDictionary* response = 234 NSDictionary* response =
193 [NotificationResponseBuilder buildDictionary:notification]; 235 [NotificationResponseBuilder buildDictionary:notification];
236 if (!NotificationPlatformBridgeMac::VerifyNotificationData(response))
237 return;
194 238
195 NSNumber* buttonIndex = 239 NSNumber* buttonIndex =
196 [response objectForKey:notification_constants::kNotificationButtonIndex]; 240 [response objectForKey:notification_constants::kNotificationButtonIndex];
197 NSNumber* operation = 241 NSNumber* operation =
198 [response objectForKey:notification_constants::kNotificationOperation]; 242 [response objectForKey:notification_constants::kNotificationOperation];
199 243
200 std::string notificationOrigin = base::SysNSStringToUTF8( 244 std::string notificationOrigin = base::SysNSStringToUTF8(
201 [response objectForKey:notification_constants::kNotificationOrigin]); 245 [response objectForKey:notification_constants::kNotificationOrigin]);
202 NSString* notificationId = [notification.userInfo 246 NSString* notificationId =
203 objectForKey:notification_constants::kNotificationId]; 247 [response objectForKey:notification_constants::kNotificationId];
204 std::string persistentNotificationId = 248 std::string persistentNotificationId =
205 base::SysNSStringToUTF8(notificationId); 249 base::SysNSStringToUTF8(notificationId);
206 int64_t persistentId; 250 int64_t persistentId;
207 if (!base::StringToInt64(persistentNotificationId, &persistentId)) { 251 if (!base::StringToInt64(persistentNotificationId, &persistentId)) {
208 LOG(ERROR) << "Unable to convert notification ID: " 252 LOG(ERROR) << "Unable to convert notification ID: "
209 << persistentNotificationId << " to integer."; 253 << persistentNotificationId << " to integer.";
210 return; 254 return;
211 } 255 }
212 std::string profileId = base::SysNSStringToUTF8( 256 std::string profileId = base::SysNSStringToUTF8(
213 [response objectForKey:notification_constants::kNotificationProfileId]); 257 [response objectForKey:notification_constants::kNotificationProfileId]);
(...skipping 10 matching lines...) Expand all
224 buttonIndex.intValue); 268 buttonIndex.intValue);
225 } 269 }
226 270
227 - (BOOL)userNotificationCenter:(NSUserNotificationCenter*)center 271 - (BOOL)userNotificationCenter:(NSUserNotificationCenter*)center
228 shouldPresentNotification:(NSUserNotification*)nsNotification { 272 shouldPresentNotification:(NSUserNotification*)nsNotification {
229 // Always display notifications, regardless of whether the app is foreground. 273 // Always display notifications, regardless of whether the app is foreground.
230 return YES; 274 return YES;
231 } 275 }
232 276
233 @end 277 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698