Skip to content

Commit

Permalink
fix type hint for CSRFProtectMiddleware (#17)
Browse files Browse the repository at this point in the history
Parameter `csrf_secret` of class `CSRFProtectMiddleware` should be of type `Optional[str]` instead of `Optional[ByteString]` as `generate_csrf` and `validate_csrf` take in `csrf_secret` as `str`.
Passing a `ByteString` as `csrf_secret` to `CSRFProtectMiddleware` cause token validation to raise `BadSignature` exception, and `validate_csrf` to raise `ValidationError('The CSRF token is invalid.')`.
  • Loading branch information
letuanhai authored Apr 9, 2024
1 parent 7334d7c commit bb6a25e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion starlette_wtf/csrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class CSRFProtectMiddleware:
def __init__(self,
app: ASGIApp,
enabled: bool=DEFAULT_ENABLED,
csrf_secret: Optional[ByteString]=DEFAULT_CSRF_SECRET,
csrf_secret: Optional[str]=DEFAULT_CSRF_SECRET,
csrf_field_name: str=DEFAULT_CSRF_FIELD_NAME,
csrf_time_limit: int=DEFAULT_CSRF_TIME_LIMIT,
csrf_headers: List[str]=DEFAULT_CSRF_HEADERS,
Expand Down

0 comments on commit bb6a25e

Please sign in to comment.