ktbs / taaabs3

A collection of web components for developing Trace Based web applications
2 stars 0 forks source link

Unwanted browser authentication dialog #4

Open hsaladin opened 4 years ago

hsaladin commented 4 years ago

In some cases, trying to access a controlled access resource triggers a native browser's authentication dialog, instead of being handled by the application.

This seems to only occur when the KTBS service hosting that resource has the same origin as the application (might be CORS related ?)

hsaladin commented 4 years ago

After deeper investigation, here is what happens :

The client part of this (= add "x-requested-with: XMLHttpRequest" request header) is easy to implement, but I haven't been able to implement the server part (= remove "WWW-Authenticate" response header). I tried to use apache's mod_header like so :

<IfModule mod_headers.c>
    <If "%{HTTP:x-requested-with} == 'XMLHttpRequest'">
        Header unset WWW-Authenticate
    </If>
</IfModule>

or with a different syntax, which should be more or less equivalent :

<IfModule mod_headers.c>
    Header unset WWW-Authenticate "expr=req('x-requested-with') == 'XMLHttpRequest' && resp('WWW-Authenticate') =~ /^Basic/"
</IfModule>

Neither of them works, apparently because mod_auth takes the precedence over mod_headers, and the directive above seems to be not evaluated when mod_auth asks for authentication.

In conclusion, I haven't been able to solve this problem with some apache tuning, as it lacks flexibility in it's authentication workflow.

pchampin commented 4 years ago

Have you tried the following rule?

<IfModule mod_headers.c>
    Header always unset WWW-Authenticate "expr=req('x-requested-with') == 'XMLHttpRequest' && resp('WWW-Authenticate') =~ /^Basic/"
</IfModule>

The difference is the keyword always after the Header directive; without it, the rule only applies to success (2xx) responses. That could explain why it does not work on 401 responses.

hsaladin commented 4 years ago

I did, and it doesn't work.

I also tried :

<IfModule mod_headers.c>
    Header always set Toto "test"
</IfModule>

=> header "Toto: test" is appended only after authentication, which confirms that during the authentication negotiation, mod_auth takes over mod_header and "Header" directives are not evaluated.

pchampin commented 4 years ago

Ok, so I agree with you: the only solution is to let kTBS manage its own authorization (authentication could still be managed by Apache, though).

This is bumps up the priority of ktbs/ktbs#81 ... :-/

pchampin commented 1 year ago

@hsaladin I believe this was since been fixed, right?