
Research
/Security News
Critical Vulnerability in NestJS Devtools: Localhost RCE via Sandbox Escape
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
functools.wraps
for endpoints decorators in FastAPI.
It updates the signature of the wrapped function with parameters defined in the decorator's wrapper function. All parameters of the wrapper function should have defaults assigned.
It's advised to name the parameter with some prefix, for example __
,
to avoid any name conflicts in decorated functions.
To use the Request object in the decorator's wrapper function
use __request: Request = Depends(get_request)
pip install fastapi-wraps
def save_request(
endpoint: Callable[P, Awaitable[RT]],
) -> Callable[P, Awaitable[RT]]:
@fastapi_wraps(endpoint)
async def wrapper(
*args: Any,
__request: Request = Depends(get_request),
__db: Db = Depends(get_db),
**kwargs: Any,
) -> RT:
__db.save(__request)
response = await endpoint(*args, **kwargs)
return response
return wrapper
app = FastAPI()
@app.get("/")
@save_request
async def hello() -> str:
return "hello"
To use dependencies provided by FastAPI's DI framework all dependencies have to be declared in the signature of the endpoint.
Hence, the decorator cannot simply use functools.wraps
, as functools.wraps
maintains the signature of the wrapped function. The fastapi_wraps
decorator takes updates the resulting signature by merging parameters from the wrapper
and the wrapped
function.
FAQs
Unknown package
We found that fastapi-wraps 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
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.