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.
Decouple complex system to separated modules by mediator.
pip install decouple
Code of example is here
from dataclasses import dataclass
from decouple import Module, Event, Mediator
class ModuleA(Module):
def __init__(self, mediator: Mediator = Mediator()):
super().__init__(mediator)
def start(self):
self.pub(StartEvent(a=7))
@dataclass
class StartEvent(Event):
a: int = 0 # must be serializable
from decouple import Module
from examples.simple.module_a import StartEvent
class ModuleB(Module):
def __init__(self):
super().__init__()
self.sub(StartEvent, self.handle_a)
def handle_start(self, event: StartEvent):
print(f'field a:{event.a}')
from examples.simple.module_a import ModuleA
from examples.simple.module_b import ModuleB
module_a = ModuleA()
module_a.add(ModuleB())
module_a.start()
Manual control
from decouple import Module
from examples.simple.module_a import StartEvent
class ModuleB(Module):
def __init__(self):
super().__init__()
# handler with higher priority will be triggered early
self.sub(StartEvent, self.handle_b, priority=0)
self.sub(StartEvent, self.handle_a, priority=100)
def handle_a(self, event: StartEvent):
# will be triggered first
print(f'field a:{event.a}')
def handle_b(self, event: StartEvent):
# will be triggered second
print(f'event.uuid:{event.uuid}, event.timestamp:{event.timestamp}')
Default priority depends on registration order
from decouple import Module
from examples.simple.module_a import StartEvent
class ModuleB(Module):
def __init__(self):
super().__init__()
# priority of handlers call increased by 1 every registration for the same event
self.sub(StartEvent, self.handle_b) # priority=1
self.sub(StartEvent, self.handle_a) # priority=2
def handle_a(self, event: StartEvent):
# will be triggered second
print(f'field a:{event.a}')
def handle_b(self, event: StartEvent):
# will be triggered first
print(f'event.uuid:{event.uuid}, event.timestamp:{event.timestamp}')
I will be glad to read your feedback in issues and pull requests.
FAQs
Decoupling logic
We found that decouple 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.