Skip to content

Commit

Permalink
Limit the max stack length
Browse files Browse the repository at this point in the history
  • Loading branch information
nicjansma committed Dec 1, 2016
1 parent b52f5b6 commit ef88f7c
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
9 changes: 9 additions & 0 deletions plugins/errors.js
Expand Up @@ -252,6 +252,11 @@ if (!Array.isArray) {
"BOOMR_plugins_errors_wrap"
];

/**
* Maximum size, in characters, of stack to capture
*/
var MAX_STACK_SIZE = 5000;

/**
* BoomerangError object
*
Expand Down Expand Up @@ -398,6 +403,10 @@ if (!Array.isArray) {

// parse the stack
if (error.stack) {
if (error.stack.length > MAX_STACK_SIZE) {
error.stack = error.stack.substr(0, MAX_STACK_SIZE);
}

frames = ErrorStackParser.parse(error);
if (frames && frames.length) {
if (error.generatedStack) {
Expand Down
22 changes: 22 additions & 0 deletions tests/page-templates/14-errors/21-max-stack.html
@@ -0,0 +1,22 @@
<%= header %>
<%= boomerangScript %>
<script src="21-max-stack.js" type="text/javascript"></script>
<script>
BOOMR_test.init({
testAfterOnBeacon: true,
Errors: {
enabled: true
}
});

var stack = "";
for (var i = 0; i < 10000; i++) {
stack += "a";
}

BOOMR.plugins.Errors.send({
stack: stack,
message: "a is not defined"
});
</script>
<%= footer %>
30 changes: 30 additions & 0 deletions tests/page-templates/14-errors/21-max-stack.js
@@ -0,0 +1,30 @@
/*eslint-env mocha*/
/*global BOOMR_test,assert*/

describe("e2e/14-errors/21-max-stack", function() {
var tf = BOOMR.plugins.TestFramework;
var t = BOOMR_test;
var C = BOOMR.utils.Compression;

it("Should have sent a single beacon", function(done) {
t.validateBeaconWasSent(done);
});

it("Should have put the err on the beacon", function() {
var b = tf.lastBeacon();
assert.isDefined(b.err);
});

it("Should have had 1 error", function() {
var b = tf.lastBeacon();
assert.equal(C.jsUrlDecompress(b.err).length, 1);
});

it("Should have had a stack with a max length of around 5000 chars", function() {
var b = tf.lastBeacon();
var err = BOOMR.plugins.Errors.decompressErrors(C.jsUrlDecompress(b.err))[0];

// allow for some wiggle room in message length, but close to 5000
assert.closeTo(err.stack.length, "a is not defined".length + 5000, 10, "stack: " + err.stack);
});
});

0 comments on commit ef88f7c

Please sign in to comment.