Registry / security / sns-validator

sns-validator

JSON →
library0.3.5jsnpmunverified

Standalone AWS SNS HTTP message validator for Node.js. Version 0.3.5. No dependency on AWS SDK. Provides signature verification for SNS notifications, subscriptions, and unsubscribe confirmations. Lightweight alternative to using the full AWS SDK for SNS validation. Works with Node.js crypto module. Not for browser use. Maintained by AWS but low release cadence (last release 2018).

npm install sns-validator
INSTALL
IMPORT
SIG · SNS-VALIDATOR
S
sns-validator
securityjavascriptv0.3.5
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MessageValidator
✓ const MessageValidator = require('sns-validator')
✗ import MessageValidator from 'sns-validator'
Package uses CommonJS. No default ES module export. Use require() or dynamic import().
new MessageValidator
✓ const validator = new MessageValidator()
✗ const validator = new MessageValidator({})
Constructor does not accept options in current version.
validate method
✓ validator.validate(messageObj, (err, message) => {})
✗ validator.validate(messageObj).then()
validate uses callback pattern, not Promises.

Shows how to validate an inbound SNS notification message using callback pattern.

const MessageValidator = require('sns-validator'); const validator = new MessageValidator(); // Example SNS message object (from HTTP POST body parsed as JSON) const message = { Type: 'Notification', MessageId: 'da41e39f-ea4d-435a-b922-c6aae3915ebe', TopicArn: 'arn:aws:sns:us-west-2:123456789012:MyTopic', Message: 'Hello from SNS!', Timestamp: '2012-05-03T23:42:17.000Z', SignatureVersion: '1', Signature: 'tcc6faL2yUC6dgZdmrwh1Y4cGa/ebXEkAi6RibDsvpi+tE/1+82j...', SigningCertUrl: 'https://sns.us-west-2.amazonaws.com/SimpleNotificationService-ac565b8b1a6c5d002d285f9598aa1d9b.pem', UnsubscribeUrl: 'https://sns.us-west-2.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-west-2:123456789012:MyTopic:2bcfbf39-05c3-41de-beaa-fcfcc21c8f55' }; validator.validate(message, (err, validatedMessage) => { if (err) { console.error('Validation failed:', err.message); process.exit(1); } console.log('Validated message:', validatedMessage); });
Debug
Known issues
gotchaThe package does not support Promises or async/await natively. You must use callbacks or wrap with util.promisify.
fix
Use util.promisify(validator.validate).call(validator, message) or wrap callback in Promise.
affects: >=0.0.0
gotchaThe validate method expects a parsed JavaScript object (result of JSON.parse), not the raw HTTP body string.
fix
Call JSON.parse on the HTTP request body before passing to validate.
affects: >=0.0.0
deprecatedPackage is in maintenance mode. Last release was in 2018. AWS recommends using the AWS SDK's SNS message validation instead.
fix
Consider using @aws-sdk/client-sns with the VerifyMessageSignature command.
affects: >=0.3.5
gotchaThe package uses Node.js crypto module and is not compatible with browser environments.
fix
Do not bundle for frontend; only use in Node.js server code.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: validator.validate is not a function
Imported incorrectly (e.g., using ES import instead of require).
fix
Use const MessageValidator = require('sns-validator');
TypeError: Cannot read property 'SigningCertUrl' of undefined
Passed raw HTTP body string instead of parsed object.
fix
Call JSON.parse(body) before passing to validate.
TypeError: callback is not a function
Called validate without a callback function.
fix
Provide a callback: validator.validate(message, (err, msg) => { ... });
Upgrade
Version history
0.3.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
21 hits · last 30 days
node
16
Amazon
1
Resources
sns-validator — npm install sns-validator · libregistry