@@ -204,7 +204,10 @@ protected String addCSRF(String html) {
204204 stringBuilder .append ("const parts = value.split(`; " );
205205 stringBuilder .append (swaggerUiConfig .getCsrf ().getCookieName ());
206206 stringBuilder .append ("=`);\n " );
207- stringBuilder .append ("if (parts.length === 2)\n " );
207+ stringBuilder .append ("const currentURL = new URL(document.URL);\n " );
208+ stringBuilder .append ("const requestURL = new URL(request.url, document.location.origin);\n " );
209+ stringBuilder .append ("const isSameOrigin = (currentURL.protocol === requestURL.protocol && currentURL.host === requestURL.host);\n " );
210+ stringBuilder .append ("if (isSameOrigin && parts.length === 2) " );
208211 stringBuilder .append ("request.headers['" );
209212 stringBuilder .append (swaggerUiConfig .getCsrf ().getHeaderName ());
210213 stringBuilder .append ("'] = parts.pop().split(';').shift();\n " );
@@ -225,6 +228,10 @@ protected String addCSRFLocalStorage(String html) {
225228 stringBuilder .append ("requestInterceptor: (request) => {\n " );
226229 stringBuilder .append ("const value = window.localStorage.getItem('" );
227230 stringBuilder .append (swaggerUiConfig .getCsrf ().getLocalStorageKey () + "');\n " );
231+ stringBuilder .append ("const currentURL = new URL(document.URL);\n " );
232+ stringBuilder .append ("const requestURL = new URL(request.url, document.location.origin);\n " );
233+ stringBuilder .append ("const isSameOrigin = (currentURL.protocol === requestURL.protocol && currentURL.host === requestURL.host);\n " );
234+ stringBuilder .append ("if (isSameOrigin) " );
228235 stringBuilder .append ("request.headers['" );
229236 stringBuilder .append (swaggerUiConfig .getCsrf ().getHeaderName ());
230237 stringBuilder .append ("'] = value;\n " );
0 commit comments