
Company News
/Security News
Socket Selected for OpenAI's Cybersecurity Grant Program
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.
is-safe-filename
Advanced tools
Check if a filename is safe to use in a path join operation
A safe filename is one that won't escape the intended directory via path traversal.
This is a purely lexical check. It does not account for symlinks that may exist on the filesystem.
npm install is-safe-filename
import isSafeFilename from 'is-safe-filename';
isSafeFilename('foo');
//=> true
isSafeFilename('../foo');
//=> false
isSafeFilename('foo/bar');
//=> false
Returns true if the filename is safe.
Throws an error if the filename is not safe.
import {assertSafeFilename} from 'is-safe-filename';
assertSafeFilename('foo');
// No error
assertSafeFilename('../foo');
//=> Error: Unsafe filename: "../foo"
A list of common unsafe filename fixtures for testing path traversal vulnerabilities.
Useful for testing that your code properly rejects unsafe filenames.
import {unsafeFilenameFixtures} from 'is-safe-filename';
for (const filename of unsafeFilenameFixtures) {
assert.throws(() => myFunction(filename));
}
FAQs
Check if a filename is safe to use in a path join operation
The npm package is-safe-filename receives a total of 844,729 weekly downloads. As such, is-safe-filename popularity was classified as popular.
We found that is-safe-filename demonstrated a healthy version release cadence and project activity because the last version was released less than 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.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.