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.
Simple implementation of chain of responsibilities
pattern.
result = chain(request) [ & DefaultLinkClass] [ | <callable|Link>] | chain
hxss.responsibility
python-hxss-responsibility
from hxss.responsibility import chain
def none(value):
pass
def increment(value):
return value + 1
def decrement(value):
return value - 1
request = 1
result = chain(request) | none | increment | decrement | chain
assert(result == 2)
result = chain(request) | none | decrement | increment | chain
assert(result == 0)
result = chain(request) | none | none | none | chain
assert(result == None)
Chain of responsibilities sequentially handles request by every link until response returned.
By default every not None
value considered as valid response(some kind of Null coalescing operator):
handled = []
def wrap(func):
def wrapper(value):
handled.append(func.__name__)
return func(value)
return wrapper
result = chain(request) \
| wrap(none) \
| wrap(increment) \
| wrap(decrement) \
| chain
assert(result == 2)
assert(handled == ['none', 'increment'])
chain
function creates new Request
callable
passed to Request
by |
operator wraps into Link
which handles the requestLink
returns valid Response
all next callables
will be ignored| chain
operator forces to return raw response valuefrom hxss.responsibility import Link
class FinalLink(Link):
def _validate_result(self, result): # see default Link implementation
return self._response(result)
result = chain(1) | FinalLink(none) | increment | decrement | chain
assert(result == None)
class CustomLink(Link):
def __init__(self):
pass
def handle(self, request):
result = calc_result(request)
return self._response(result)
result = chain(1) | increment | CustomLink() | decrement | chain
class InversedLink(Link):
def _validate_result(self, result):
if (result is None):
return self._response(result)
result = chain(1) & InversedLink | increment | CustomLink() | decrement | chain
assert(result == None)
FAQs
Simple implementation of `chain of responsibilities` pattern
We found that hxss.responsibility 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.