[Pkg-javascript-commits] [ltx] 83/469: connection: optionally enforce maxStanzaSize, default 64KB for router
Jonas Smedegaard
dr at jones.dk
Wed Aug 31 13:01:06 UTC 2016
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository ltx.
commit 210f3ab514213e68d471777c1334dedb2229890c
Author: Astro <astro at spaceboyz.net>
Date: Mon Sep 6 00:46:12 2010 +0200
connection: optionally enforce maxStanzaSize, default 64KB for router
---
lib/xmpp/connection.js | 16 +++++++++++++---
lib/xmpp/router.js | 4 +++-
2 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/lib/xmpp/connection.js b/lib/xmpp/connection.js
index 4ad7da6..a291cc9 100644
--- a/lib/xmpp/connection.js
+++ b/lib/xmpp/connection.js
@@ -39,6 +39,7 @@ exports.makeConnection = makeConnection;
*/
function initConnection(conn) {
conn.charset = 'UTF-8';
+ conn.bytesParsed = 0;
conn.addListener('data', conn.onData);
conn.addListener('end', conn.onEnd);
@@ -86,11 +87,12 @@ Connection.prototype.startParser = function() {
/* Notify in case we don't wait for <stream:features/> (Component)
*/
self.emit('streamStart', attrs);
- } else {
+ } else {
var child = new xml.Element(name, attrs);
if (!self.element) {
/* A new stanza */
self.element = self.addStreamNs(child);
+ self.bytesParsedOnStanzaBegin = self.bytesParsed;
} else {
/* A child element of a stanza */
self.element = self.element.cnode(child);
@@ -107,6 +109,7 @@ Connection.prototype.startParser = function() {
/* Stanza complete */
self.onStanza(self.element);
self.element = null;
+ delete self.bytesParsedOnStanzaBegin;
}
} else {
self.error('xml-not-well-formed', 'XML parse error');
@@ -129,9 +132,16 @@ Connection.prototype.startStream = function() {
Connection.prototype.onData = function(data) {
if (this.parser) {
+ if (this.bytesParsedOnStanzaBegin && this.maxStanzaSize &&
+ this.bytesParsed > this.bytesParsedOnStanzaBegin + this.maxStanzaSize) {
+
+ this.error('policy-violation', 'Maximum stanza size exceeded');
+ return;
+ }
+ this.bytesParsed += data.length;
+
if (!this.parser.parse(data, false)) {
- this.emit('error', 'XMPP parse error');
- this.end();
+ this.error('xml-not-well-formed', 'XML parse error');
}
}
};
diff --git a/lib/xmpp/router.js b/lib/xmpp/router.js
index 4def02c..d1e8c1c 100644
--- a/lib/xmpp/router.js
+++ b/lib/xmpp/router.js
@@ -89,6 +89,7 @@ DomainContext.prototype.getOutStream = function(domain) {
dbgStream('outgoing', outStream);
StreamShaper.attach(outStream, this.router.rateLimit);
+ outStream.maxStanzaSize = this.router.maxStanzaSize;
this.setupStream(domain, outStream);
outStream.addListener('close', function() {
@@ -217,7 +218,6 @@ DomainContext.prototype.receive = function(stanza) {
* * nameprep
* * timeouts
* * keepAlive
- * * stanza size limit
* * TLS
*/
function Router(s2sPort) {
@@ -231,11 +231,13 @@ function Router(s2sPort) {
exports.Router = Router;
Router.prototype.rateLimit = 1E6; // 100 KB/s, it's S2S after all
+Router.prototype.maxStanzaSize = 65536; // 64 KB, by convention
Router.prototype.acceptConnection = function(inStream) {
var self = this;
Server.makeIncomingServer(inStream);
+ inStream.maxStanzaSize = this.maxStanzaSize;
StreamShaper.attach(inStream, this.rateLimit);
console.log('INCOMING from ' + inStream.remoteAddress);
dbgStream('incoming', inStream);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/ltx.git
More information about the Pkg-javascript-commits
mailing list