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.
It's a micro library for manipulating sys.displayhook
.
When you need to change the standard behavior of displayhook
, with this library you will do it:
Install it:
pip install displayhooks
And use:
import sys
from displayhooks import not_display
not_display(int)
sys.displayhook('Most of the adventures recorded in this book really occurred; one or two were experiences of my own, the rest those of boys who were schoolmates of mine.')
#> 'Most of the adventures recorded in this book really occurred; one or two were experiences of my own, the rest those of boys who were schoolmates of mine.'
sys.displayhook(666)
# [nothing!]
You can declaratively declare a converter function for the printed values. What it returns will be used to call the original displayhook
function.
import sys
from displayhooks import converted_displayhook
@converted_displayhook
def new_displayhook(value):
return value.lower()
sys.displayhook("What’s gone with that boy, I wonder? You TOM!")
#> 'what’s gone with that boy, i wonder? you tom!'
If your function returns None
, nothing will be printed.
You can disable the display of certain data types, similar to how NoneType
values are ignored by default.
You could already see a similar example above, let's look at it again:
import sys
from types import FunctionType
from displayhooks import not_display
not_display(FunctionType)
sys.displayhook('Nothing! Look at your hands. And look at your mouth. What is that truck?')
#> 'Nothing! Look at your hands. And look at your mouth. What is that truck?'
sys.displayhook(lambda x: x)
# [nothing!]
In this example, you can see that we have disabled the display for functions, but all other data types are displayed unchanged.
You can limit the impact on sys.displayhook
only to the code inside a function. If you hang the autorestore_displayhook
decorator on it, after exiting the function, the displayhook that was installed before it was called will be automatically restored:
import sys
from types import FunctionType
from displayhooks import not_display, autorestore_displayhook
@autorestore_displayhook
def do_something_dangerous():
not_display(FunctionType)
sys.displayhook(do_something_dangerous)
# [nothing!]
do_something_dangerous()
sys.displayhook(do_something_dangerous)
#> <function do_something_dangerous at 0x104c980e0>
FAQs
Extend the capabilities of the standard displayhook in Python
We found that displayhooks 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.