GithubHelp home page GithubHelp logo

Comments (11)

Tratcher avatar Tratcher commented on June 27, 2024

What sort of response action? Does it need to be run even for failed requests?

Most response actions take place in OnSendingHeaders (unless you're buffering or there is no response body).

from security.

BadriL avatar BadriL commented on June 27, 2024

Yes, I'm buffering the response and I need to write the buffer back to the network stream even if there is a failure (whatever is in the buffer at that point).

from security.

Tratcher avatar Tratcher commented on June 27, 2024

If there is a failure I don't think you should write out the buffer, you should let the failed request handling take over instead. That said, you would still need to put the original response stream back in so the error handler could write to it.

I'll take a look at the object model and see if we can call Teardown in a finally block.

from security.

BadriL avatar BadriL commented on June 27, 2024

Yes, that's a good point. I need to put the original stream back in. BTW, had I not buffered, the response produced thus far would have gone out isn't it? Is it not correct to write the buffer back? Sure, the error handler should respond back but any pointers on how to go about with the response produced till that point. Just discard?

from security.

Tratcher avatar Tratcher commented on June 27, 2024

Yes, I would just discard the response in an error case. The error handling logic can produce better results if the response body hasn't been sent yet, and a partial response body isn't useful to anyone anyways.

from security.

BadriL avatar BadriL commented on June 27, 2024

There could be a problem in putting TeardownAsync in a finally block in AuthenticationMiddleware. TeardownAsync also calls ApplyResponseAsync, which in turn calls ApplyResponseGrantAsync and ApplyResponseChallengeAsync. When there is an exception, not sure if it is a good idea to send a challenge or grant. So, as part of this, you may want to consider separating the teardown part and the response handling part and ensure only the teardown part is called even if there is an exception.

from security.

Tratcher avatar Tratcher commented on June 27, 2024

Yeah, I was considering how to deal with that case. One option is to pass in a flag to these APIs indicating if this was a success or failed response. They could then choose if they want to do any work. Your example of wanting to replace the response body is one of the few where I think it makes sense to do work during an unhandled error.

from security.

Tratcher avatar Tratcher commented on June 27, 2024

Ah, here's an idea. TeardownAsync calls both ApplyResponseAsync and TeardownCoreAsync. I could skip ApplyResponseAsync in error cases and just run TeardownCoreAsync, which you could override to put the stream back (if it didn't happen inside of ApplyResponseAsync).

from security.

BadriL avatar BadriL commented on June 27, 2024

Yes, that will work. I do not think anyone would be needing to send challenge or grant in case of an exception and hence there may not be a need to pass the flag and let the derived classes decide to do anything about it. I think this approach will be better, for this does not disturb the existing setup and only ensures TeardownCoreAsync runs even if there is an exception, which is exactly what I want :). Thanks much.

from security.

Tratcher avatar Tratcher commented on June 27, 2024

@loudej @davidfowl

from security.

Tratcher avatar Tratcher commented on June 27, 2024

Related problem: https://katanaproject.codeplex.com/workitem/360
Exceptions thrown in the ApplyResponse code path get cached and re-thrown durring OnSendingHeaders, breaking error handling scenarios like ErrorPage or ErrorHandler.

from security.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.