Skip to content

Commit 5274d62

Browse files
Artiom CiumacArtiom Ciumacjakelacey2012
authored
fix: support signed logout resposne sent via POST (#140)
Co-authored-by: Artiom Ciumac <artiom.ciumac@okta.com> Co-authored-by: Jake Lacey <jakewlacey@gmail.com>
1 parent 2ab371b commit 5274d62

3 files changed

Lines changed: 41 additions & 14 deletions

File tree

lib/utils.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,12 @@ module.exports.validateSignature = validateSignature;
185185
function validateSignature(req, element_type, xml, options) {
186186
const type = constants.ELEMENTS[element_type].PROP;
187187

188-
const isRequestSigned = !options.deflate ?
188+
const isPostOrWithoutDeflate = (req.body && req.body[type]) || !options.deflate;
189+
const isRequestSigned = isPostOrWithoutDeflate ?
189190
xpath.select(options.signaturePath || constants.ELEMENTS[element_type].SIGNATURE_VALIDATION_PATH, xml).length > 0 : !!req.query.Signature;
190191

191192
if (isRequestSigned) {
192-
if ((req.body && req.body[type]) || !options.deflate) {
193+
if (isPostOrWithoutDeflate) {
193194
// HTTP-POST or HTTP-Redirect without deflate encoding
194195
const validationErrors = signers.validateXmlEmbeddedSignature(xml, options);
195196
if (validationErrors && validationErrors.length > 0) {

test/fixture/signed_response.js

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/utils.tests.js

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,45 @@
1-
const timekeeper = require('timekeeper');
2-
const expect = require('chai').expect;
1+
const timekeeper = require("timekeeper");
2+
const DOMParser = require("@auth0/xmldom").DOMParser;
3+
const expect = require("chai").expect;
34

4-
const utils = require('../lib/utils');
5+
const utils = require("../lib/utils");
56

6-
describe('utils', function () {
7-
describe('generateInstant', function () {
8-
it('should pad the millis appropriately', function () {
7+
const signedResponse = require("./fixture/signed_response");
8+
9+
describe("utils", function () {
10+
describe("generateInstant", function () {
11+
it("should pad the millis appropriately", function () {
912
timekeeper.withFreeze(0, () => {
10-
expect(utils.generateInstant()).to.equal('1970-01-01T00:00:00.000Z');
13+
expect(utils.generateInstant()).to.equal("1970-01-01T00:00:00.000Z");
1114
});
1215
});
1316
});
14-
describe('generateUniqueID', function() {
15-
it('should generate an ID 20 chars long', function() {
17+
describe("generateUniqueID", function () {
18+
it("should generate an ID 20 chars long", function () {
1619
expect(utils.generateUniqueID().length).to.equal(20);
1720
});
1821
});
19-
describe('generateUniqueID', function() {
20-
it('should generate an ID from the alphabet', function() {
21-
expect('abcdef0123456789'.split('')).to.include.members(utils.generateUniqueID().split(''));
22+
describe("generateUniqueID", function () {
23+
it("should generate an ID from the alphabet", function () {
24+
expect("abcdef0123456789".split("")).to.include.members(
25+
utils.generateUniqueID().split("")
26+
);
27+
});
28+
});
29+
describe("validateSignature", function () {
30+
describe("with custom signing certificate", function () {
31+
it("should validate the signature correctly", function () {
32+
const response = signedResponse.response;
33+
34+
const req = { body: { SAMLResponse: response }, query: {} };
35+
const element_type = "LOGOUT_RESPONSE";
36+
const xml = new DOMParser().parseFromString(signedResponse.xml);
37+
const options = { signingCert: signedResponse.cert, deflate: true };
38+
39+
// should not throw errors
40+
expect(utils.validateSignature(req, element_type, xml, options)).to.be
41+
.undefined;
42+
});
2243
});
2344
});
2445
});

0 commit comments

Comments
 (0)