-
Notifications
You must be signed in to change notification settings - Fork 416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rule for wildcard CORS in FastAPI #3137
Conversation
|
Thanks for the feedback, @inkz. I've updated the rule. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change code of the test to the following (I cant edit your branch):
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
app = FastAPI()
origins = ["*"]
app.add_middleware(
CORSMiddleware,
# rule-id: wildcard-cors
allow_origins=origins,
allow_credentials=True,
allow=["*"]
)
app.add_middleware(
CORSMiddleware,
# rule-id: wildcard-cors
allow_origins=["*"],
allow_credentials=True,
allow=["*"]
)
app.add_middleware(
CORSMiddleware,
# ok-id: wildcard-cors
allow_origins=["https://github.com"],
allow_credentials=True,
allow=["*"]
)
app.add_middleware(
CORSMiddleware,
# ok: wildcard-cors
allow_origins=["https://github.com"],
allow_credentials=True,
allow=["www.semgrep.dev"]
)
@app.get("/")
async def main():
return {"message": "Hello Semgrep"}
@inkz It's done. |
@theinfosecguy
should work this time 😄 there must be |
hahah, my bad. 😆 Should work now. |
ok now lgtm! thank you! |
FastAPI supports adding middleware using
app.add_middleware()
. Developers usually add a wildcard origin policy, that can lead to security risks.