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

Side by Side Diff: mojo/public/js/bindings/router.js

Issue 406993002: Validate incoming JS Message Headers Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 define("mojo/public/js/bindings/router", [ 5 define("mojo/public/js/bindings/router", [
6 "console",
abarth-chromium 2014/07/22 03:51:00 Production code shouldn't use |console|
hansmuller 2014/07/22 15:49:06 OK, I'll remove that.
6 "mojo/public/js/bindings/codec", 7 "mojo/public/js/bindings/codec",
7 "mojo/public/js/bindings/connector", 8 "mojo/public/js/bindings/connector",
8 ], function(codec, connector) { 9 "mojo/public/js/bindings/validator",
10 ], function(console, codec, connector, validator) {
9 11
10 function Router(handle) { 12 function Router(handle) {
11 this.connector_ = new connector.Connector(handle); 13 this.connector_ = new connector.Connector(handle);
12 this.incomingReceiver_ = null; 14 this.incomingReceiver_ = null;
13 this.nextRequestID_ = 0; 15 this.nextRequestID_ = 0;
14 this.responders_ = {}; 16 this.responders_ = {};
15 17
16 this.connector_.setIncomingReceiver({ 18 this.connector_.setIncomingReceiver({
17 accept: this.handleIncomingMessage_.bind(this), 19 accept: this.handleIncomingMessage_.bind(this),
18 }); 20 });
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 55
54 Router.prototype.setIncomingReceiver = function(receiver) { 56 Router.prototype.setIncomingReceiver = function(receiver) {
55 this.incomingReceiver_ = receiver; 57 this.incomingReceiver_ = receiver;
56 }; 58 };
57 59
58 Router.prototype.encounteredError = function() { 60 Router.prototype.encounteredError = function() {
59 return this.connector_.encounteredError(); 61 return this.connector_.encounteredError();
60 }; 62 };
61 63
62 Router.prototype.handleIncomingMessage_ = function(message) { 64 Router.prototype.handleIncomingMessage_ = function(message) {
63 var flags = message.getFlags(); 65 var err = validator.validateMessageHeader(message);
66 if (err != validator.ValidationError.NONE)
67 this.close();
68
69 var flags = message.getHeaderFlags();
64 if (flags & codec.kMessageExpectsResponse) { 70 if (flags & codec.kMessageExpectsResponse) {
65 if (this.incomingReceiver_) { 71 if (this.incomingReceiver_) {
66 this.incomingReceiver_.acceptWithResponder(message, this); 72 this.incomingReceiver_.acceptWithResponder(message, this);
67 } else { 73 } else {
68 // If we receive a request expecting a response when the client is not 74 // If we receive a request expecting a response when the client is not
69 // listening, then we have no choice but to tear down the pipe. 75 // listening, then we have no choice but to tear down the pipe.
70 this.close(); 76 this.close();
71 } 77 }
72 } else if (flags & codec.kMessageIsResponse) { 78 } else if (flags & codec.kMessageIsResponse) {
73 var reader = new codec.MessageReader(message); 79 var reader = new codec.MessageReader(message);
(...skipping 10 matching lines...) Expand all
84 Router.prototype.handleConnectionError_ = function(result) { 90 Router.prototype.handleConnectionError_ = function(result) {
85 for (var each in this.responders_) 91 for (var each in this.responders_)
86 this.responders_[each].reject(result); 92 this.responders_[each].reject(result);
87 this.close(); 93 this.close();
88 }; 94 };
89 95
90 var exports = {}; 96 var exports = {};
91 exports.Router = Router; 97 exports.Router = Router;
92 return exports; 98 return exports;
93 }); 99 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698