Skip to content
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

Ability for Fairings to respond to requests #2219

Closed
jprider63 opened this issue Jun 3, 2022 · 2 comments
Closed

Ability for Fairings to respond to requests #2219

jprider63 opened this issue Jun 3, 2022 · 2 comments
Labels
duplicate This issue or pull request already exists

Comments

@jprider63
Copy link

Is your feature request motivated by a concrete problem? Please describe.

I'm attempting to extend rocket_csrf with the ability to automatically check whether valid CSRF tokens are provided in headers. If an invalid token is provided for a write request, I would like the fairing to respond with a permission denied error, but the API does not allow this.

I understand that the philosophy is to respond to requests via request guards or response callbacks, however I believe fairings are the right place for this functionality since this needs to be run on every request. Otherwise, users would need to remember to add request guards to every request and failure to do so would be a security issue.

Why this feature can't or shouldn't live outside of Rocket

The Fairing trait does not give us the ability to abort requests via on_request.

Ideal Solution

Update on_request to give us the ability to respond to requests. Maybe the return type should be something like Option<rocket::request::Outcome>.

Alternatives Considered

The only other approach I've seen to do this is to modify the request to point to a handler defined by the fairing. I'll probably do this for now, but it seems like a hack.

@jprider63 jprider63 added the request Request for new functionality label Jun 3, 2022
@SergioBenitez
Copy link
Member

This is planned. See #749. Indeed, the workaround, well, works, but is unfortunate.

@SergioBenitez SergioBenitez added duplicate This issue or pull request already exists and removed request Request for new functionality labels Jun 3, 2022
@jprider63
Copy link
Author

Thanks! Let me know if I can help with the design or implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants