question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dependecies are available as query params?

See original GitHub issue

Example

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:closed
  • Created 3 years ago
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
sepermancommented, Nov 27, 2020

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.

1reaction
Mausecommented, Nov 27, 2020

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found