Skip to content

Commit de154c8

Browse files
committed
Fix vulnerability
1 parent 55921cd commit de154c8

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

services/src/main/java/org/fao/geonet/api/records/MetadataApi.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,9 @@ public String getRecord(
198198
HttpServletRequest request
199199
)
200200
throws Exception {
201+
AbstractMetadata metadata;
201202
try {
202-
ApiUtils.canViewRecord(metadataUuid, request);
203+
metadata = ApiUtils.canViewRecord(metadataUuid, request);
203204
} catch (SecurityException e) {
204205
Log.debug(API.LOG_MODULE_NAME, e.getMessage(), e);
205206
throw new NotAllowedException(ApiParams.API_RESPONSE_NOT_ALLOWED_CAN_VIEW);
@@ -208,15 +209,16 @@ public String getRecord(
208209
String acceptHeader = StringUtils.isBlank(request.getHeader(HttpHeaders.ACCEPT)) ? MediaType.APPLICATION_XML_VALUE : request.getHeader(HttpHeaders.ACCEPT);
209210
List<String> accept = Arrays.asList(acceptHeader.split(","));
210211

211-
String formatterBasePath = metadataUuid + "/formatters/";
212+
// Use the uuid from the abstract metadata instead of the path variable to address URL forwarding vulnerabilities
213+
String formatterBasePath = metadata.getUuid() + "/formatters/";
212214
String defaultFormatterPath = formatterBasePath + "xsl-view";
213215
if (accept.contains(MediaType.TEXT_HTML_VALUE) || accept.contains(MediaType.APPLICATION_XHTML_XML_VALUE)) {
214216
// Check if the language query parameter is a real language supported by the system. If not, fallback to the request language.
215217
String resolvedLanguage = (StringUtils.isNotBlank(language) && languageUtils.getUiLanguages().contains(language.toLowerCase()))
216218
? language.toLowerCase()
217219
: languageUtils.getIso3langCode(request.getLocales());
218220
// If there is a redirect to a record view formatter configured use it, otherwise fallback to the default xsl-view formatter.
219-
String redirect = getRecordViewFormatterRedirect(resolvedLanguage, metadataUuid, recordViewFormatter);
221+
String redirect = getRecordViewFormatterRedirect(resolvedLanguage, metadata.getUuid(), recordViewFormatter);
220222
if (StringUtils.isNotBlank(redirect)) {
221223
return redirect;
222224
}

0 commit comments

Comments
 (0)