Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

authheaders

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

authheaders - npm Package Compare versions

Comparing version 0.0.2 to 1.0.0

50

index.js

@@ -40,2 +40,4 @@ const path = require('path');

const KEYS = ['spf', 'dkim', 'arc', 'dmarc'];
function authenticateMessage(message, ...args) {

@@ -61,3 +63,49 @@ const command = `python3 ${scripts.authenticateMessage} ${args.join(' ')}`;

if (stderr.length > 0) return reject(new Error(stderr.join('')));
resolve(stdout.join(''));
// Authentication-Results: mx1.forwardemail.net; spf=fail reason="SPF fail - not authorized" smtp.helo=jacks-macbook-pro.local smtp.mailfrom=foo@forwardemail.net; dkim=fail; arc=none; dmarc=fail (Used From Domain Record) header.from=forwardemail.net policy.dmarc=reject
const result = { header: stdout.join('').trim() };
for (const key of KEYS) {
result[key] = {};
}
result.dmarc.policy = 'none';
const terms = result.header
.split(/;/)
.map((t) => t.trim())
.filter((t) => t !== '');
for (const term of terms) {
const split = term.split('=');
if (term.startsWith('spf=')) {
result.spf.result = split[1].split(' ')[0];
const index = term.indexOf('reason=');
if (index !== -1)
result.spf.reason = term
.slice(index + 'reason='.length)
.split('"')[1];
} else if (term.startsWith('dkim=')) {
result.dkim.result = split[1].split(' ')[0];
const index = term.indexOf('(');
if (index !== -1)
result.dkim.reason = term.slice(index + '('.length).split(')')[0];
} else if (term.startsWith('arc=')) {
result.arc.result = split[1].split(' ')[0];
// TODO: right now this does not return a comment due to this issue:
// <https://github.com/ValiMail/authentication-headers/issues/12
} else if (term.startsWith('dmarc=')) {
result.dmarc.result = split[1].split(' ')[0];
// reason
const index = term.indexOf('(');
if (index !== -1)
result.dmarc.reason = term.slice(index + '('.length).split(')')[0];
// policy
const policyIndex = term.indexOf('policy.dmarc=');
if (policyIndex !== -1)
result.dmarc.policy = term
.slice(policyIndex + 'policy.dmarc='.length)
.split(' ')[0];
}
}
resolve(result);
});

@@ -64,0 +112,0 @@ });

2

package.json
{
"name": "authheaders",
"description": "Node.js wrapper around the Python pip package authheaders",
"version": "0.0.2",
"version": "1.0.0",
"author": "Nick Baugh <niftylettuce@gmail.com> (http://niftylettuce.com/)",

@@ -6,0 +6,0 @@ "bugs": {

@@ -97,5 +97,17 @@ # authheaders

The value of `result` is an String with the new Authentication-Results header to add to the top of the message headers.
The value of `result` is an Object with properties `header` (String), and Objects for `spf`, `dkim`, `arc`, and `dmarc`. These Object's contain a `result` (String) and conditionally a `reason` (String) value.
An example `result` object is provided below:
```js
{
header: 'Authentication-Results: example.com; spf=none smtp.helo=domain.of.sender.net smtp.mailfrom=test.com; dkim=pass header.d=forwardemail.net; arc=pass; dmarc=fail (Used From Domain Record) header.from=gmail.com policy.dmarc=none',
spf: { result: 'none' },
dkim: { result: 'pass' },
arc: { result: 'pass' },
dmarc: { policy: 'none', result: 'fail', reason: 'Used From Domain Record' }
}
```
## Contributors

@@ -102,0 +114,0 @@

@@ -32,6 +32,20 @@ const fs = require('fs');

t.is(
result,
'Authentication-Results: example.com; spf=none smtp.helo=domain.of.sender.net smtp.mailfrom=test.com; dkim=pass header.d=forwardemail.net; arc=pass; dmarc=fail (Used From Domain Record) header.from=gmail.com policy.dmarc=none'
);
t.deepEqual(result, {
arc: {
result: 'pass'
},
dkim: {
result: 'pass'
},
dmarc: {
policy: 'none',
reason: 'Used From Domain Record',
result: 'fail'
},
header:
'Authentication-Results: example.com; spf=none smtp.helo=domain.of.sender.net smtp.mailfrom=test.com; dkim=pass header.d=forwardemail.net; arc=pass; dmarc=fail (Used From Domain Record) header.from=gmail.com policy.dmarc=none',
spf: {
result: 'none'
}
});
});

@@ -50,3 +64,2 @@

);
t.pass();
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc