Skip to content

Commit

Permalink
Merge pull request #41732 from nextcloud/backport/41632/stable28
Browse files Browse the repository at this point in the history
[stable28] Fix adding x-requested-with header for relative URLs in some cases
  • Loading branch information
AndyScherzinger authored Nov 27, 2023
2 parents 057daae + d52641b commit 4342a48
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
15 changes: 13 additions & 2 deletions core/src/utils/xhr-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,25 @@

import { getRootUrl } from '@nextcloud/router'

/**
*
* @param {string} url the URL to check
* @returns {boolean}
*/
const isRelativeUrl = (url) => {
return !url.startsWith('https://') && !url.startsWith('http://')
}

/**
* @param {string} url The URL to check
* @return {boolean} true if the URL points to this nextcloud instance
*/
const isNextcloudUrl = (url) => {
const nextcloudBaseUrl = window.location.protocol + '//' + window.location.host + getRootUrl()
// try with relative and absolute URL
return url.startsWith(nextcloudBaseUrl) || url.startsWith(getRootUrl())
// if the URL is absolute and starts with the baseUrl+rootUrl
// OR if the URL is relative and starts with rootUrl
return url.startsWith(nextcloudBaseUrl)
|| (isRelativeUrl(url) && url.startsWith(getRootUrl()))
}

/**
Expand Down
4 changes: 2 additions & 2 deletions dist/core-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/core-main.js.map

Large diffs are not rendered by default.

0 comments on commit 4342a48

Please sign in to comment.