@@ -204,7 +204,10 @@ protected String addCSRF(String html) {
204
204
stringBuilder .append ("const parts = value.split(`; " );
205
205
stringBuilder .append (swaggerUiConfig .getCsrf ().getCookieName ());
206
206
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) " );
208
211
stringBuilder .append ("request.headers['" );
209
212
stringBuilder .append (swaggerUiConfig .getCsrf ().getHeaderName ());
210
213
stringBuilder .append ("'] = parts.pop().split(';').shift();\n " );
@@ -225,6 +228,10 @@ protected String addCSRFLocalStorage(String html) {
225
228
stringBuilder .append ("requestInterceptor: (request) => {\n " );
226
229
stringBuilder .append ("const value = window.localStorage.getItem('" );
227
230
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) " );
228
235
stringBuilder .append ("request.headers['" );
229
236
stringBuilder .append (swaggerUiConfig .getCsrf ().getHeaderName ());
230
237
stringBuilder .append ("'] = value;\n " );
0 commit comments