Research
Recent Trends in Malicious Packages Targeting Discord
The Socket research team breaks down a sampling of malicious packages that download and execute files, among other suspicious behaviors, targeting the popular Discord platform.
asgi-cors-middleware
Readme
Python package that allows whitelisting of urls on ASGI applications making it possible to perform cross origin requests from the browser.
Cross-Origin Resource Sharing (CORS) allows a server to define any origins other than its own that are safe for the browser to load resources from.
Mozilla does a good job of explaining CORS here.
Assuming you have a web application that follows a client-server architecture, it's possible the frontend would be running on a server different from the API. If the frontend application made a request to the API, this kind of request would be blocked by the browser.
For security reasons, browsers block cross origin requests by default.
A cross origin request is a request made to a server with a different url/ origin. To mitigate around this, we could simply add the url of the frontend application as an allowed origin on the API server. Most web frameworks provide a way to do this or have third party libraries that achieve the same.
asgi-cors-middleware aims to provide a simple way to achieve the above for ASGI applications.
Can be installed via pip
pip install asgi-cors-middleware
To use the middleware, just import it like so:
from asgi_cors_middleware import CorsASGIApp
To start whitelisting origins, just wrap your asgi application instance with
CorsASGIApp
.
app = CorsASGIApp(
app=asgi_app_instance,
origins=["www.example.com"]
)
A simple HelloWorld application that whitelists the origins below:
pip install uvicorn
Create a file called example.py and update it with the code below:
from asgi_cors_middleware import CorsASGIApp
class HelloWorld:
def __init__(self, scope):
pass
async def __call__(self, receive, send):
await send({
'type': 'http.response.start',
'status': 200,
'headers': [
[b'content-type', b'text/plain'],
]
})
await send({
'type': 'http.response.body',
'body': b'Hello, world!',
})
app = CorsASGIApp(
app=HelloWorld,
origins=[
"www.example.com",
"localhost:9000"
]
)
That's it. For real, that's really it. Now your application is all set to allow requests from www.example.com and localhost:9000.
uvicorn example:app
For guidance and instructions, please see CONTRIBUTING.md
FAQs
Whitelist urls on ASGI applications allowing for cross origin requests
We found that asgi-cors-middleware 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
The Socket research team breaks down a sampling of malicious packages that download and execute files, among other suspicious behaviors, targeting the popular Discord platform.
Security News
Socket CEO Feross Aboukhadijeh joins a16z partners to discuss how modern, sophisticated supply chain attacks require AI-driven defenses and explore the challenges and solutions in leveraging AI for threat detection early in the development life cycle.
Security News
NIST's new AI Risk Management Framework aims to enhance the security and reliability of generative AI systems and address the unique challenges of malicious AI exploits.