<div dir="ltr">Hi All,<div><br></div><div>I'm attempting to get CORs working with some shibboleth protected resources and am running into an issue.</div><div><br></div><div>My setup is as follows:<br><br></div><div><font face="monospace">server-a ( web application )</font></div><div><font face="monospace">server-b ( web service api )</font></div><div><font face="monospace">server-c ( shibboleth idp )</font></div><div><br>Server A is configured to use the following binding as recommended by this document.</div><div><br></div><div>Document:</div><div><a href="https://wiki.shibboleth.net/confluence/display/KB/Cross-origin+AJAX+requests+for+Shib-protected+resources">https://wiki.shibboleth.net/confluence/display/KB/Cross-origin+AJAX+requests+for+Shib-protected+resources</a><br></div><div><br>Binding:</div><div>outgoingBindings="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"<br></div><div><br></div><div>Apache's mod_headers is able to correctly apply the CORs related headers on server-b and server-c once cookies have been retrieved. However, on the first request before I've received a cookie for server-b, it seems that mod_shib intercepts the request since no valid cookie was sent ( as expected ) but does not apply any headers to the response containing the auth form ( sourced from "/etc/shibboleth/bindingTemplate.html" ) causing the request to fail in the browser due to no matching "Access-Control-Allow-Origin" header being present.</div><div><br></div><div>Does anyone have this working configuration for this or have any tips to get mod_shib to apply headers here?</div><div><br></div><div>I've tried to apply these headers both narrowly scoped to the specific Shibboleth.SSO <Location>s or as broadly as the whole <VirtualHost> but they never seem to get applied to the response for the intercepted requests.<br><br><font face="monospace">SetEnvIf Origin "^http(s)?://(.*\.my\.super\.domain)(:\d+)?$" AccessControlAllowOrigin=$0<br>Header always set Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin<br>Header always set Access-Control-Allow-Credentials true env=AccessControlAllowOrigin<br>Header always set Access-Control-Allow-Headers "X-Requested-With, Content-Type, Origin, Authorization, Accept, Client-Security-Token, Accept-Encoding"<br>Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"<br></font></div><div><br></div><div>I was actually able to get this to work in Google Chrome using, (outgoingBindings="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect) on the service provider but wasn't able to recreate that success in Safari, Firefox, or Edge due to differences in the way each browser handles the 302 redirects, applies "Origin" header, interprets CORs policy, etc. I was able to get this to work in chrome with that binding by applying the following config in apache.</div><div><br></div><div>( The gist is that on some of the redirects "Origin" isn't sent in the request headers. "Referer" on the other hand is set and we can use it to check if the source is from a trusted domain as we do when "Origin" is set. But in the case that "Referer" matches our rule and "Origin" is undefined, we return "null" for the value of "Access-Control-Allow-Origin", Doing this causes the CORs policy evaluation to succeed in chrome, we're able to get our cookie back and successfully make cross origin requests to server b both initially and on subsequent requests. )</div><div><br></div><div><font face="monospace">SetEnvIf Referer "^http(s)?://(.*\.my\.super\.domain)(:\d+)?/?.*?$" AccessControlAllowReferer=null<br>Header always set Access-Control-Allow-Origin %{AccessControlAllowReferer}e env=AccessControlAllowReferer<br>Header always set Access-Control-Allow-Credentials true env=AccessControlAllowReferer</font><br><br><br><font face="monospace">SetEnvIf Origin "^http(s)?://(.*\.my\.super\.domain)(:\d+)?$" AccessControlAllowOrigin=$0<br>Header always set Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin<br>Header always set Access-Control-Allow-Credentials true env=AccessControlAllowOrigin<br><br>Header always set Access-Control-Allow-Headers "X-Requested-With, Content-Type, Origin, Authorization, Accept, Client-Security-Token, Accept-Encoding"<br>Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"</font><br></div><div><br></div><div>This is the javascript code that works with chrome:<br><a href="https://gist.github.com/bgeels/f7e109e2372142c9faea99ef489db0b5">https://gist.github.com/bgeels/f7e109e2372142c9faea99ef489db0b5</a><br></div><div><br></div><div>Despite this working in chrome, I think if I can figure out a way to apply the headers to the first request to server b that's intercepted by mod_shib using the "HTTP-POST" binding, the javascript implementation for the shibboleth auth handshake would be much more straightforward and would have a higher success rate across browsers.</div><div><br></div><div>Any assistance would be greatly appreciated.</div><div><br></div><div>Thanks!</div><div>Ben</div></div>