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.
🚀 The Starlette events bridge that you need. 🚀
Documentation: https://starlette-bridge.tarsild.io 📚
Source Code: https://github.com/tarsil/starlette-bridge
Starlette has evolved and it will keep on growing. In the release 0.26+ it was announced the
on_startup
and on_shutdown
events would be removed in favour of the newly lifepsan
and those
would be officially removed in the release 1.0.
The problem is the fact that there are a lof od packages out there still using the old ways of using the events and this change will introduce breaking changes.
This bridge will make sure that doesn't happen and you can still use the old form of using the
on_startup
and on_shutdown
without breaking the lifespan
from Starlette.
What Starlette Bridge
does for you is simple. It gets the on_startup
and on_shutdown
events
in the same fashion you could do before and internally generates the newly lifespan
for starlette.
That simple. Keeping the old syntax intact and using the newly lifespan
.
To install Starlette Bridge, simply run:
$ pip install starlette-bridge
This is actually very simple to do it. You don't need to do anything particularly difficult, in fact, you only need to update where your Starlette object comes from.
from starlette_bridge import Starlette
app = Starlette()
And that is pretty much it.
Starlette bridge simply maps your on_startup
and on_shutdown
events and converts them into
the new lifespan
async generator from Starlette
.
This way you can continue to use your preferred way of assembling the events while maintaining the new structure required by Starlette for managing events.
These two pieces of functionality are also supported by the bridge making sure that what you had in the past, still remains working as is without changing the syntax.
Let us see an example how it works. We will be using Starlette Bridge because already contains events we want to use.
Using the on_startup
and on_shutdown
.
from saffier import Database, Registry
from starlette_bridge import Starlette
database = Database("sqlite:///db.sqlite")
models = Registry(database=database)
app = Starlette(
on_startup=[database.connect],
on_shutdown=[database.disconnect],
)
You can, of course, use the lifespan as well.
from contextlib import asynccontextmanager
from saffier import Database, Registry
from starlette_bridge import Starlette
database = Database("sqlite:///db.sqlite")
models = Registry(database=database)
@asynccontextmanager
async def lifespan(app: Starlette):
# On startup
await database.connect()
yield
# On shutdown
await database.disconnect()
app = Starlette(lifespan=lifespan)
As mentioned before, those two functionalities are also available.
from saffier import Database, Registry
from starlette_bridge import Starlette
database = Database("sqlite:///db.sqlite")
models = Registry(database=database)
app = Starlette()
@app.on_event("startup")
async def start_database():
await database.connect()
@app.on_event("shutdown")
async def close_database():
await database.disconnect()
from saffier import Database, Registry
from starlette_bridge import Starlette
database = Database("sqlite:///db.sqlite")
models = Registry(database=database)
app = Starlette()
app.add_event_handler("startup", database.connect)
app.add_event_handler("shutdown", database.disconnect)
This is from the same author of Esmerald, Saffier and Asyncz. Have a look around those techologies as well 😄.
FAQs
The Starlette events bridge that you need.
We found that starlette-bridge 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.