-
-
Notifications
You must be signed in to change notification settings - Fork 492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DOI / Update DOI widget in editor #8468
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,8 +31,9 @@ | |
*/ | ||
module.service("gnDoiService", [ | ||
"$http", | ||
"$q", | ||
"gnConfig", | ||
function ($http, gnConfig) { | ||
function ($http, $q, gnConfig) { | ||
/** | ||
* Returns a promise to validate a metadata to be published on a DOI server. | ||
* | ||
|
@@ -65,7 +66,29 @@ | |
* @returns {*} | ||
*/ | ||
function getDoiServersForMetadata(metadataId) { | ||
return $http.get("../api/doiservers/metadata/" + metadataId); | ||
return $http.get("../api/doiservers/metadata/" + metadataId, { cache: true }); | ||
} | ||
|
||
/** | ||
* Return the DOI server with a prefix matching the DOI url. | ||
*/ | ||
function getDoiServerForMetadataAndDoi(metadataId, doiUrl) { | ||
var deferred = $q.defer(); | ||
getDoiServersForMetadata(metadataId).then( | ||
function (response) { | ||
for (var i = 0; i < response.data.length; i++) { | ||
if (doiUrl.match("doi.org/" + response.data[i].prefix)) { | ||
deferred.resolve(response.data[i]); | ||
return; | ||
} | ||
} | ||
deferred.reject(null); | ||
}, | ||
function () { | ||
deferred.reject(null); | ||
} | ||
); | ||
return deferred.promise; | ||
} | ||
|
||
function isDoiApplicableForMetadata(md) { | ||
|
@@ -85,24 +108,55 @@ | |
* the metadata is published. | ||
* | ||
*/ | ||
function canPublishDoiForResource(md, resource) { | ||
function canPublishDoiForResource(md, doiUrl) { | ||
if (doiUrl == null || doiUrl.indexOf("doi.org/") === -1) { | ||
return false; | ||
} | ||
|
||
var doiKey = gnConfig["system.publication.doi.doikey"]; | ||
var isMdWorkflowEnableForMetadata = | ||
gnConfig["metadata.workflow.enable"] && md.draft === "y"; | ||
return ( | ||
isDoiApplicableForMetadata(md) && | ||
resource.lUrl !== null && | ||
resource.lUrl.match("doi.org/" + doiKey) !== null && | ||
doiUrl.match("doi.org/" + doiKey) !== null && | ||
!isMdWorkflowEnableForMetadata | ||
); | ||
} | ||
|
||
function checkDoiManagementForResource(md, resource) { | ||
if (resource.locUrl == null || resource.locUrl.indexOf("doi.org/") === -1) { | ||
Check failure Code scanning / CodeQL Incomplete URL substring sanitization High
'
doi.org/ Error loading related location Loading |
||
return; | ||
} | ||
var doiKey = null; | ||
getDoiServersForMetadata(md.id).then(function (response) { | ||
var isMdWorkflowEnableForMetadata = | ||
gnConfig["metadata.workflow.enable"] && md.draft === "y"; | ||
for (var i = 0; i < response.data.length; i++) { | ||
if (resource.locUrl.match("doi.org/" + response.data[i].prefix)) { | ||
doiKey = response.data[i].prefix; | ||
break; | ||
} | ||
} | ||
if (doiKey !== null) { | ||
if ( | ||
isDoiApplicableForMetadata(md) && | ||
resource.locUrl.match("doi.org/" + doiKey) !== null && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check seems a bit redundant with the check done in https://github.com/geonetwork/core-geonetwork/pull/8468/files#diff-031877af43ecd9313d60230ea5001dac1160701606a4fea6c33b0cd15d476beaR135, no? |
||
!isMdWorkflowEnableForMetadata | ||
) { | ||
resource.canManageDoi = true; | ||
} | ||
} | ||
}); | ||
} | ||
|
||
return { | ||
check: check, | ||
create: create, | ||
isDoiApplicableForMetadata: isDoiApplicableForMetadata, | ||
canPublishDoiForResource: canPublishDoiForResource, | ||
getDoiServersForMetadata: getDoiServersForMetadata | ||
getDoiServersForMetadata: getDoiServersForMetadata, | ||
checkDoiManagementForResource: checkDoiManagementForResource, | ||
getDoiServerForMetadataAndDoi: getDoiServerForMetadataAndDoi | ||
}; | ||
} | ||
]); | ||
|
Check failure
Code scanning / CodeQL
Incomplete URL substring sanitization High
Copilot Autofix AI 3 months ago
To fix the problem, we need to ensure that the URL is parsed and the host is explicitly checked against a whitelist of allowed hosts. This will prevent attackers from embedding "doi.org/" in unexpected parts of the URL. We will use the
URL
constructor available in modern JavaScript to parse the URL and then check the host.doiUrl
using theURL
constructor.