New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

express-security-txt

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-security-txt - npm Package Compare versions

Comparing version 2.4.0 to 2.5.0

32

__tests__/formatPolicy.test.js

@@ -145,2 +145,4 @@ const securityTxt = require('../index')

global.console.warn = jest.fn()
const res = securityTxt.formatSecurityPolicy(options)

@@ -152,2 +154,32 @@

)
expect(global.console.warn).toHaveBeenCalled()
})
test('preferredLanguages directive works with multiple values', () => {
const options = {
contact: 'mailto:security@example.com',
preferredLanguages: ['en', 'ru', 'es']
}
const res = securityTxt.formatSecurityPolicy(options)
expect(res).toBe(
'Contact: mailto:security@example.com\n' +
'Preferred-Languages: en, ru, es\n'
)
})
test('preferredLanguages directive works with one value only', () => {
const options = {
contact: 'mailto:security@example.com',
preferredLanguages: 'en'
}
const res = securityTxt.formatSecurityPolicy(options)
expect(res).toBe(
'Contact: mailto:security@example.com\n' +
'Preferred-Languages: en\n'
)
})

@@ -220,1 +220,33 @@ const securityTxt = require('../index')

})
test('validate successfully for the preferredLanguages key', () => {
const optionsWithArray = {
contact: '...',
preferredLanguages: ['en', 'es']
}
const optionsWithString = {
contact: '...',
preferredLanguages: 'ru'
}
const optionsWithComment = {
contact: '...',
preferredLanguages: { comment: 'I am fluent in these', value: ['en', 'ru'] }
}
expect(() => securityTxt.validatePolicyFields(optionsWithArray)).not.toThrow()
expect(() => securityTxt.validatePolicyFields(optionsWithString)).not.toThrow()
expect(() => securityTxt.validatePolicyFields(optionsWithComment)).not.toThrow()
})
test('validate fails if Array<object> fed to preferredLanguages', () => {
const options = {
contact: '...',
preferredLanguages: [
{ comment: '...', value: 'en' }
]
}
expect(() => securityTxt.validatePolicyFields(options).toThrow())
})

11

index.js
'use strict'
const Joi = require('joi')
const DIRECTIVES = ['Contact', 'Encryption', 'Acknowledgments', 'Signature', 'Policy', 'Hiring', 'Permission']
const DIRECTIVES = ['Contact', 'Encryption', 'Acknowledgments', 'Preferred-Languages', 'Signature', 'Policy', 'Hiring', 'Permission']

@@ -107,2 +107,10 @@ /**

// For the other fields, arrays are used to represent multiple occurences
// of a field. However, for the Preferred-Language: directive, an array shows
// a comma separated list. Convert the provided array into an array of one
// value: a string with commas.
if (outputDirective === 'Preferred-Languages') {
value = [ value.map(languageCode => languageCode.trim()).join(', ') ]
}
value.forEach(valueOption => {

@@ -191,2 +199,3 @@ if (valueOption.hasOwnProperty('value')) {

encryption: fieldValue({ singleValue: string.regex(/^(?!http:)/i) }),
preferredLanguages: fieldValue({ canBeArray: false, singleValue: array.items(string) }),
policy: fieldValue(),

@@ -193,0 +202,0 @@ hiring: fieldValue(),

2

package.json
{
"name": "express-security-txt",
"version": "2.4.0",
"version": "2.5.0",
"description": "Express middleware that implements a security.txt path and policy",

@@ -5,0 +5,0 @@ "main": "index.js",

Sorry, the diff of this file is not supported yet

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