Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support signed logout response sent via POST #140

Merged
merged 2 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,12 @@ module.exports.validateSignature = validateSignature;
function validateSignature(req, element_type, xml, options) {
const type = constants.ELEMENTS[element_type].PROP;

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

if (isRequestSigned) {
if ((req.body && req.body[type]) || !options.deflate) {
if (isPostOrWithoutDeflate) {
// HTTP-POST or HTTP-Redirect without deflate encoding
const validationErrors = signers.validateXmlEmbeddedSignature(xml, options);
if (validationErrors && validationErrors.length > 0) {
Expand Down
5 changes: 5 additions & 0 deletions test/fixture/signed_response.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 33 additions & 12 deletions test/utils.tests.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,45 @@
const timekeeper = require('timekeeper');
const expect = require('chai').expect;
const timekeeper = require("timekeeper");
const DOMParser = require("@auth0/xmldom").DOMParser;
const expect = require("chai").expect;

const utils = require('../lib/utils');
const utils = require("../lib/utils");

describe('utils', function () {
describe('generateInstant', function () {
it('should pad the millis appropriately', function () {
const signedResponse = require("./fixture/signed_response");

describe("utils", function () {
describe("generateInstant", function () {
it("should pad the millis appropriately", function () {
timekeeper.withFreeze(0, () => {
expect(utils.generateInstant()).to.equal('1970-01-01T00:00:00.000Z');
expect(utils.generateInstant()).to.equal("1970-01-01T00:00:00.000Z");
});
});
});
describe('generateUniqueID', function() {
it('should generate an ID 20 chars long', function() {
describe("generateUniqueID", function () {
it("should generate an ID 20 chars long", function () {
expect(utils.generateUniqueID().length).to.equal(20);
});
});
describe('generateUniqueID', function() {
it('should generate an ID from the alphabet', function() {
expect('abcdef0123456789'.split('')).to.include.members(utils.generateUniqueID().split(''));
describe("generateUniqueID", function () {
it("should generate an ID from the alphabet", function () {
expect("abcdef0123456789".split("")).to.include.members(
utils.generateUniqueID().split("")
);
});
});
describe("validateSignature", function () {
describe("with custom signing certificate", function () {
it("should validate the signature correctly", function () {
const response = signedResponse.response;

const req = { body: { SAMLResponse: response }, query: {} };
const element_type = "LOGOUT_RESPONSE";
const xml = new DOMParser().parseFromString(signedResponse.xml);
const options = { signingCert: signedResponse.cert, deflate: true };

// should not throw errors
expect(utils.validateSignature(req, element_type, xml, options)).to.be
.undefined;
});
});
});
});
Loading