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

wrap-authorization ignores 'raised' unauthorized exceptions in async mode #88

Open
mszajna opened this issue May 14, 2020 · 0 comments
Open

Comments

@mszajna
Copy link

mszajna commented May 14, 2020

With Ring 3-arity contract, exceptions thrown in the same thread bubble back to the middleware. However, if any non-blocking IO was to happen between wrap-authorization and throw-unauthorized, those exceptions would arrive via raise callback. One such instance could be a OAuth2 authorization backend calling the token endpoint. A simplified example:

(defn handler [request respond raise]
  (future ; simulates non-blocking IO switching threads
    (try
      (throw-unauthorized) ; simplified example
      (catch Throwable t (raise t))))) ; raise any handler exceptions per Ring spec

(-> handler
    (wrap-authorization nil) ; backend doesn't get called anyway
    (apply {:request-method :get} println println nil)) ; run it
; => #ExceptionInfo
; expected: wrap-authorization to catch the raised exception
; and handle it with the backend

Possible fix

(defn wrap-authorization
  (fn
    ; [...]
    ([request respond raise]
     (try (handler request respond
           (fn [e] (try (respond (authorization-error request e backend))
                     (catch Throwable t (raise t))))
          (catch Exception e
            (respond (authorization-error request e backend)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant