Dependecies are available as query params?
See original GitHub issueExample
Here is a code from the official Fastapi relational tutorial
@app.get("/users/", response_model=List[schemas.User])
def read_users(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
users = crud.get_users(db, skip=skip, limit=limit)
return users
Description
db is supposed to be a SQLAlchemy session, but it will be also available to be set as a URL parameters. This seems like potentially a security issue. Basically one can pass GET /users/?db=foo
which will cause an internal server error because “foo” does not have query
or add
attributes that are needed from a SQLAlchemy session. The question is if there can be a string that can be passed as db and gets de-serialized into a Python object that has the Session interface? How can the “db” dependency be inaccessible as a http query param?
Environment
- OS: Linux
- FastAPI Version 0.61.2
To know the FastAPI version use:
python -c "import fastapi; print(fastapi.__version__)"
- Python version: 3.8.6
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (8 by maintainers)
Top Results From Across the Web
Advanced Dependencies - FastAPI
Let's imagine that we want to have a dependency that checks if the query parameter q contains some fixed content. But we want...
Read more >use-query-params - npm
Start using use-query-params in your project by running `npm i use-query-params`. There are 79 other projects in the npm registry using ...
Read more >Handling inter-parameter dependencies in REST APIs with ...
An inter-parameter dependency is a constraint between two or more input parameters of an API that must be satisfied to form a valid...
Read more >kimaramyz/use-query-params - NPM Package Overview
@kimaramyz/use-query-params is a library of React hooks for using URL query params as state. Light-weight, TS support and no dependencies.
Read more >Inject query parameter into dependency provider factory in ...
If I understand correctly you want to take the query param backend from your path programatically. You can use the Angular Router like...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I see. It was not clear to me that the dependencies’ parameters will end up as URL params. Is it mentioned in the docs? Perhaps I missed it. Thanks for the clarification.
Those two lines aren’t your issue - the session=None parameter you have declared is.
That is how you declare URL parameters in FastAPI, even in subdependencies - this is not a bug