
Research
Security News
Lazarus Strikes npm Again with New Wave of Malicious Packages
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
django-websocket-request
Advanced tools
Support for Django's request/response lifecycle to automatically handle WebSocket messages.
This package provides support for transport agnostic routing to allow the Django's request/response lifecycle to automatically WebSocket messages. It borrows a WebSocket message format from Sails.js.
Install using pip
...
$ pip install django-websocket-request
# Set Django Environment
os.environ['DJANGO_SETTINGS_MODULE'] = 'django_project.settings'
from wsrequest import WebSocketRequest
message = '{"method": "GET", "url": "/api/projects/"}'
request = WebSocketRequest(message)
response = request.get_response()
print(response.content)
The method key can be any HTTP method: GET, POST, PUT, DELETE, PATCH, HEAD, or OPTIONS. The url key is an absolute URL without the domain name. The data key is an optional dictionary in which the key-value pairs in used to create the method’s data payload. The token key is also optional, and used to recreate an HTTP Authorization header, Authorization: JWT YOUR_TOKEN_HERE. If you're using Django REST framework, you might like to check out django-rest-framework-jwt.
{
"method": "POST",
"url": "/api/companies/",
"data": {
"name": "Acme Inc."
},
"token": "MY_JSON_WEB_TOKEN"
}
Check out GetBlimp/django-websocket-request-example for an example implementation and a live demo.
import os
import json
from tornado import web, ioloop
from sockjs.tornado import SockJSRouter, SockJSConnection
# Set Django Environment
os.environ['DJANGO_SETTINGS_MODULE'] = 'django_project.settings'
from wsrequest import WebSocketRequest
class RESTAPIConnection(SockJSConnection):
def on_open(self, info):
self.send(json.dumps({'connected': True}))
def on_message(self, data):
response = WebSocketRequest(data).get_response()
self.send(response.content)
if __name__ == '__main__':
import logging
port = 8080
logging.getLogger().setLevel(logging.INFO)
Router = SockJSRouter(RESTAPIConnection, '/ws/api')
app = web.Application(Router.urls)
app.listen(port)
logging.info(" [*] Listening on 0.0.0.0:{}".format(port))
ioloop.IOLoop.instance().start()
FAQs
Support for Django's request/response lifecycle to automatically handle WebSocket messages.
We found that django-websocket-request 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
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.
Security News
Opengrep continues building momentum with the alpha release of its Playground tool, demonstrating the project's rapid evolution just two months after its initial launch.