Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
infer-owner
Advanced tools
Infer the owner of a path based on the owner of its nearest existing parent
The infer-owner npm package is designed to infer the owner of a file or directory based on the ownership of its parent directories. It is particularly useful in file system operations where maintaining the correct file ownership is crucial, such as in deployment scripts or file management utilities. This package helps ensure that files and directories are created with the appropriate ownership, reflecting the ownership of their parent directories, thus maintaining consistency and security in file operations.
Infer ownership of a file or directory
This feature allows you to infer the ownership (user ID and group ID) of a file or directory by analyzing its parent directories. The function returns a Promise that resolves with an object containing the `uid` and `gid` of the inferred owner.
const inferOwner = require('infer-owner');
inferOwner('/path/to/file/or/directory').then(owner => {
console.log(owner); // { uid: 1000, gid: 1000 }
});
Similar to infer-owner, chownr is designed to recursively change the ownership of a directory (and its contents) to the specified user and group. While infer-owner infers the ownership from existing parent directories, chownr requires the user to explicitly specify the desired ownership.
fs-extra extends the built-in Node.js fs module with additional functionality, including methods for changing file ownership. Although fs-extra does not specifically focus on inferring ownership like infer-owner, it provides a broader set of file system operations, including changing ownership.
Infer the owner of a path based on the owner of its nearest existing parent
const inferOwner = require('infer-owner')
inferOwner('/some/cache/folder/file').then(owner => {
// owner is {uid, gid} that should be attached to
// the /some/cache/folder/file, based on ownership
// of /some/cache/folder, /some/cache, /some, or /,
// whichever is the first to exist
})
// same, but not async
const owner = inferOwner.sync('/some/cache/folder/file')
// results are cached! to reset the cache (eg, to change
// permissions for whatever reason), do this:
inferOwner.clearCache()
This module endeavors to be as performant as possible. Parallel requests for ownership of the same path will only stat the directories one time.
inferOwner(path) -> Promise<{ uid, gid }>
If the path exists, return its uid and gid. If it does not, look to its parent, then its grandparent, and so on.
inferOwner(path) -> { uid, gid }
Sync form of inferOwner(path)
.
inferOwner.clearCache()
Delete all cached ownership information and in-flight tracking.
FAQs
Infer the owner of a path based on the owner of its nearest existing parent
The npm package infer-owner receives a total of 7,648,368 weekly downloads. As such, infer-owner popularity was classified as popular.
We found that infer-owner demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.