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.
A simple IOC / Dependency injection micro framework for Python.
Suppose you are tasked with implementing a library which does some task, the specification for which is...
For the purpose of your library, you only need to implement part of the specification, but you want to leave it open ended so other libraries / programs can extend what you have done to fit their needs.
This is what injecty is for!
pip install injecty
Take the task of processing lists containing hashes representing 2D shapes and calculate the area of each:
[
{"type": "Circle", radius: 2.0},
{"type": "Square", length: 3},
...
]
You create a python library for this task - let's call it shape_area_calculator.
You may start by defining an abstract base class with a method for calculating area
Your main method for parsing the shapes may look like this
Next, you might define implementations for circle and square
With injecty, your code for a parser may look like this.
Injecty finds implementations using config modules. These are any top level module with a name matching
injecty_config_*
(e.g.: injecty_config_shapes.py). Each config module must have:
So in this example, the author of a program could add a dependency on this library and define their own processors for any other shape (e.g.: Rectangle) by defining their class and creating a config module for it (e.g.: injecty_config_rectangle.py)
Often - the ordering of implementations is important. Taking the shape example above - suppose the input data did not
contain an explicit type
attribute. In that case, the program would have to examine the other attributes to determine
if a type is suitable. It is considered to be a circle if the input has a radius
. If the input has a length
, it is
a square. If the input has both a length
and a height
, it is a rectangle.
In order to make sure that we don't confuse a rectangle for a square, we would need to make sure the rectangle check is done BEFORE the square check. Remember, the original program has no knowledge of rectangles. So we accomplish this using implementation ordering.
You can pass a sort_key
into any of the injecty get_impl
methods. If no explicit
sort_key is given, Injecty examines the base class to see if there is an integer priority attribute, and sorts
implementations in descending order. So in this case, simply by giving Rectangle a higher priority than Square, we
would ensure that processing occurs correctly.
The typical process here is:
Quality
workflows make sure that your PR
meets the styling, linting, and code coverage standards).FAQs
A simple IOC / Dependency injection micro framework for Python.
We found that injecty 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.
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.