Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Parses SAML responses into JS objects you can read and manipulate.
$ npm install saml2js --save
Saml2js supports Node.js 0.10+ and iojs.
Saml2js was designed for use in any Node.js environment whether that's a web app or a standalone script.
var express = require('express')
Saml2js = require('saml2js'),
app = express();
app.post('/saml/callback/?', function(req, res, next){
var parser = new Saml2js(res.body.SAMLResponse);
res.json(parser.asObject());
});
app.listen(3000);
To instantiate a new SAML parser:
var Saml2js = require('saml2js');
var parser = new Saml2js(SAMLResponse);
After passing your SAML response as a string to the constructor you now have access to the following methods.
toObject()
Returns the parsed SAML as a JavaScript object.
var parsedObject = parser.asObject();
Note that if your SAML has attributes have a Name
attribute that contains a string that is mixed case and contains spaces Saml2js will automatically camel case this name when it is added as a property on the resulting object.
Example:
Given the following SAML...
<saml2:Attribute Name="First Name">
<saml2:AttributeValue>John</saml2:AttributeValue>
</saml2:Attribute>
The resulting JavaScript object returned from Saml2js().asObject()
will look like this:
{
firstName: 'John'
}
toJSON()
Returns parsed SAML as a JSON string. Once you've instantiated the module and passed it raw SAML you can get its value as a JSON string with parser.toJSON()
.
get()
Returns the value of a SAML attribute by name. The name you pass to this function should be the same as what the attribute value in your SAML is. For example, given this SAML:
<saml2:Attribute Name="First Name">
<saml2:AttributeValue>John</saml2:AttributeValue>
</saml2:Attribute>
To get the value of First Name
you would call it like this:
// assuming you've instantiated the library as `parser` with `new Saml2js(SAMLResponse)`...
var firstName = parser.get('first name');
console.log(firstName); //=> 'John'
You don't need to worry about case sensitivity. Internally the Lodash .camelCase()
method is called on the string you pass so when it is compared against the parsed SAML it will automagically match the name of the key as its stored internally if it exists.
parse()
This is a private method. It is called internally when you pass your SAML to the constructor. You should never need to call this manually. See the source code if you want to know more about it.
Testing requires Mocha and Chai.
npm install && npm install -g mocha
mocha
When contributing, be sure to branch off of develop
to get the latest changes. Contributions are welcome. Please try to write tests for your code so we can merge it in faster.
This is a fork of saml2json by John Flesch. Thanks for your original work.
Modified work Copyright (c) 2015 Aplo LLC, https://aploquote.com Original work Copyright (c) 2013 John Flesch, http://fles.ch
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Parse SAML2 attributes into a JavaScript object.
We found that saml2js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.