Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Commit

Permalink
Add tests for DoS via header
Browse files Browse the repository at this point in the history
  • Loading branch information
remy committed Jan 21, 2016
1 parent ccebde4 commit 3fd1e20
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,33 @@ describe('Server', function () {
});
});

describe('authenticateBewit()', function () {

it('errors on uri too long', function (done) {

var long = '/';
for (var i = 0; i < 5000; ++i) {
long += 'x';
}

var req = {
method: 'GET',
url: long,
host: 'example.com',
port: 8080,
authorization: 'Hawk id="1", ts="1353788437", nonce="k3j4h2", mac="zy79QQ5/EYFmQqutVnYb73gAc/U=", ext="hello"'
};

Hawk.server.authenticateBewit(req, credentialsFunc, {}, function (err, credentials, bewit) {

expect(err).to.exist();
expect(err.output.statusCode).to.equal(400);
expect(err.message).to.equal('Resource path exceeds max length');
done();
});
});
});

describe('authenticateMessage()', function () {

it('errors on invalid authorization (ts)', function (done) {
Expand Down
28 changes: 28 additions & 0 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,34 @@ describe('Utils', function () {
expect(host.name).to.equal('[123:123:123]');
done();
});

it('errors on header too long', function (done) {

var long = '';
for (var i = 0; i < 5000; ++i) {
long += 'x';
}

expect(Hawk.utils.parseHost({ headers: { host: long } })).to.be.null();
done();
});
});

describe('parseAuthorizationHeader()', function () {

it('errors on header too long', function (done) {

var long = 'Scheme a="';
for (var i = 0; i < 5000; ++i) {
long += 'x';
}
long += '"';

var err = Hawk.utils.parseAuthorizationHeader(long, ['a']);
expect(err).to.be.instanceof(Error);
expect(err.message).to.equal('Header length too long');
done();
});
});

describe('version()', function () {
Expand Down

0 comments on commit 3fd1e20

Please sign in to comment.