Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Main focus is an easy way to create lazy universally injectable dependencies; in less magical way. It also leans more on the side of making it easier to get the dependency you need anywhere in the codebase.
py-xinject allows you to easily inject lazily created universal dependencies into whatever code that needs them, in an easy to understand and self-documenting way.
📄 Detailed Documentation | 🐍 PyPi
# via pip
pip install xinject
# via poetry
poetry add xinject
# This is the "my_resources.py" file/module.
import boto3
from xinject import DependencyPerThread
class S3(DependencyPerThread):
def __init__(self, **kwargs):
# Keeping this simple; a more complex version
# may store the `kwargs` and lazily create the s3 resource
# only when it's asked for (via a `@property or some such).
self.resource = boto3.resource('s3', **kwargs)
To use this resource in codebase, you can do this:
# This is the "my_functions.py" file/module
from .my_resources import S3
def download_file(file_name, dest_path):
# Get dependency
s3_resource = S3.grab().resource
s3_resource.Bucket('my-bucket').download_file(file_name, dest_path)
Inject a different version of the resource:
from .my_resources import S3
from .my_functions import download_file
us_west_s3_resource = S3(region_name='us-west-2')
def get_s3_file_from_us_west(file, dest_path):
# Can use Dependencies as a context-manager,
# inject `use_west_s3_resource` inside `with`:
with us_west_s3_resource:
download_file(file, dest_path)
# Can also use Dependencies as a function decorator,
# inject `use_west_s3_resource` whenever this method is called.
@us_west_s3_resource
def get_s3_file_from_us_west(file, dest_path):
download_file(file, dest_path)
This library is licensed under the MIT-0 License. See the LICENSE file.
FAQs
Lazy dependency injection.
We found that xinject 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
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.