Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Validate, sanitize and transform values with proper types.
🔎 Validation: checks a value (example: check if value is string)
⚙ Sanitization: if a value is not valid, try to transform it (example: transform value to Date
)
🛠️ Transformation: transforms a value (example: parse JSON)
🔌 Schemas are functions: easily extendable
Validation only checks the provided value and returns it with proper types.
import { validate } from 'fefe'
const validatePerson = validate.object({ name: validate.string() })
// result is of type { name: string }
const person = validatePerson({ name: 'Leia' })
// throws FefeError because 'foo' is not a valid property
validatePerson({ foo: 'bar' })
You can also use fefe
to define your types easily:
type Person = ReturnType<typeof validatePerson> // { name: string }
import { sanitize, validate } from 'fefe'
const sanitizeMovie = validate.object({
title: validate.string(),
releasedAt: sanitize.date()
})
// { title: string, releasedAt: Date }
type Movie = ReturnType<typeof sanitizeMovie>
const book: Book = sanitizeMovie({
title: 'Star Wars',
releasedAt: '1977-05-25T12:00:00.000Z'
})
Then book
equals { title: 'Star Wars', releasedAt: Date(1977-05-25T12:00:00.000Z) }
(releasedAt
now is a date).
This is an example that can be applied to parsing environment variables or query string parameters. Note how easy it is to apply a chain of functions to transform and validate a value (here we use ramda
).
import { transform, validate } from 'fefe'
import { pipe } from 'ramda'
const parseConfig = validate.object({
gcloudCredentials: pipe(
validate.string(),
transform.parseJson(),
validate.object({ key: validate.string() })
),
whitelist: pipe(validate.string(), str => str.split(','))
})
// { gcloudCredentials: { key: string }, whitelist: string[] }
type Config = ReturnType<typeof parseConfig>
const config: Config = parseConfig({
gcloudCredentials: '{"key":"secret"}',
whitelist: 'alice,bob'
})
Then config
will equal { gcloudCredentials: { key: 'secret'}, whitelist: ['alice', 'bob'] }
.
Note: you can use validations in transformations.
FAQs
Validate, sanitize and transform values with proper types.
The npm package fefe receives a total of 44 weekly downloads. As such, fefe popularity was classified as not popular.
We found that fefe 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
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.