Skip to content

Commit f8d5fab

Browse files
committed
Add QuickJS engine compatibility.
1 parent f633d36 commit f8d5fab

File tree

1 file changed

+25
-27
lines changed

1 file changed

+25
-27
lines changed

saml_sp.js

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
/*
22
* JavaScript functions for providing SAML SP with NGINX Plus
33
*
4-
* Copyright (C) 2023 Nginx, Inc.
4+
* Copyright (C) 2025 Nginx, Inc.
55
*/
66

7-
export default {
8-
handleSingleSignOn, // Process SAML Response form IdP
9-
handleSingleLogout, // Process SAML LogoutRequest and LogoutResponse from IdP
10-
handleAllMessages, // Process all SAML messages from IdP
11-
initiateSingleSignOn, // Initiate SAML SSO by redirecting to IdP
12-
initiateSingleLogout // Initiate SAML SLO by redirecting to IdP
13-
};
14-
15-
const xml = require("xml");
16-
const zlib = require("zlib");
17-
const querystring = require("querystring");
18-
const fs = require("fs");
7+
import xml from 'xml';
8+
import zlib from 'zlib';
9+
import querystring from 'querystring';
10+
import fs from 'fs';
1911

2012
const initiateSingleSignOn = produceSAMLMessage.bind(null, "AuthnRequest");
2113
const initiateSingleLogout = produceSAMLMessage.bind(null, "LogoutRequest");
@@ -1321,22 +1313,20 @@ function parseConfigurationOptions(r, messageType) {
13211313
}
13221314

13231315
function getEscapeXML() {
1324-
const fpc = Function.prototype.call;
1325-
const _replace = fpc.bind(fpc, String.prototype.replace);
1326-
1327-
const tbl = {
1328-
'<': '&lt;',
1329-
'>': '&gt;',
1330-
"'": '&apos;',
1331-
'"': '&quot;',
1332-
'&': '&amp;',
1316+
const escapeMap = {
1317+
'<': '&lt;',
1318+
'>': '&gt;',
1319+
"'": '&apos;',
1320+
'"': '&quot;',
1321+
'&': '&amp;'
13331322
};
1334-
tbl.__proto__ = null;
13351323

1336-
return function (str) {
1337-
return _replace(str, /[<>'"&]/g, c => tbl[c]);
1338-
}
1339-
};
1324+
return function escapeXML(str) {
1325+
if (str == null) return '';
1326+
1327+
return String(str).replace(/[<>'"&]/g, character => escapeMap[character]);
1328+
};
1329+
}
13401330

13411331
function isUrlOrUrn(str) {
13421332
const urlRegEx = /^((?:(?:https?):)\/\/)?((?:(?:[^:@]+(?::[^:@]+)?|[^:@]+@[^:@]+)(?::\d+)?)|(?:\[[a-fA-F0-9:]+]))(\/(?:[^?#]*))?(\\?(?:[^#]*))?(#(?:.*))?$/;
@@ -1373,3 +1363,11 @@ function readKeysFromFile(keyFile) {
13731363
throw Error(`Failed to read private or public key from file "${keyFile}": ${e.message}`);
13741364
}
13751365
}
1366+
1367+
export default {
1368+
handleSingleSignOn, // Process SAML Response form IdP
1369+
handleSingleLogout, // Process SAML LogoutRequest and LogoutResponse from IdP
1370+
handleAllMessages, // Process all SAML messages from IdP
1371+
initiateSingleSignOn, // Initiate SAML SSO by redirecting to IdP
1372+
initiateSingleLogout // Initiate SAML SLO by redirecting to IdP
1373+
};

0 commit comments

Comments
 (0)