-
Couldn't load subscription status.
- Fork 48
Fix ConvertToEdoc:getRealPath() - Incorrect Real Path Check Causing Asset Removal #106
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
base: main
Are you sure you want to change the base?
Fix ConvertToEdoc:getRealPath() - Incorrect Real Path Check Causing Asset Removal #106
Conversation
…, and link tags using realPath
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More information needed. Please demonstrate where and how this fails, and how to test if it's fixed.
The intention of this method is to filter invalid relative paths from being executed in eForms. If a relative URI does not have a valid "real path" in the system, it will not be used See comment on line 517:
/*
* NO EXTERNAL LINKS. These are removed.
* eForms are often imported from unknown sources.
* Developers tend to use insecure CDN's, links to images, tracking tokens,
* and advertisements.
*/
|
Code: /*
* NO EXTERNAL LINKS. These are removed.
* eForms are often imported from unknown sources.
* Developers tend to use insecure CDN's, links to images, tracking tokens,
* and advertisements.
*/
if(path.startsWith("http") || path.startsWith("HTTP")) {
element.remove();
}
// internal GET links are validated.
else if( path.contains("?") ) {
// image or link paths with parameters
parameters = path.split("\\?")[1];
}
else if(! path.isEmpty()) {
// these are most likely relative context paths
path = getRealPath( path );
if(! path.isEmpty()) {
potentialFilePaths.add(path);
}
}There are three main conditions in the above code:
✅ I’ve fixed the logic related to this third condition ( To reproduce the issue on the
|
20240814-QA-1 branch Approved-by: Keith Chung
|
Not sure I follow. |
|
Sorry for the confusing explanation. I will try to explain the issue again: The issue is in the method private static String getRealPath(String uri) {
String contextRealPath = "";
logger.debug("Context path set to " + contextPath);
if (ConvertToEdoc.contextPath != null && ConvertToEdoc.realPath != null) {
logger.debug("Relative file path " + uri);
contextRealPath = Paths.get(ConvertToEdoc.realPath, ConvertToEdoc.realPath).toAbsolutePath().toString();
}
logger.debug("Absolute file path " + contextRealPath);
return contextRealPath;
}
Now, before I explain the issue, I have to mention that two static class-level variables are being used in the In this PR, I have initialized these variables correctly while saving the eForm ( Now, the issue:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Form with Image</title>
</head>
<body>
<form action="#" method="post">
<script src="${oscar_javascript_path}jquery/jquery-3.6.4.min.js"></script>
<img src="${oscar_image_path}labreq3.png" alt="Sample Image">
</form>
</body>
</html>
<form action="../eform/addEForm.do?efmfid=91&efmdemographic_no=1&efmprovider_no=999998&eform_link=null" name="saveEForm" method="POST">
<script src="/oscar/library/jquery/jquery-3.6.4.min.js"></script>
<img src="../eform/displayImage.do?imagefile=labreq3.png" alt="Sample Image" />
<input type="hidden" id="otherFaxInput" />
<div id="eformPageSpacer" class="hidden-print DoNotPrint no-print" style="position: absolute; left: 0px; width: 100%; margin: 0px; padding: 0px; height: 1px;"></div>
<input id="subject" name="subject" type="hidden" />
<div id="attachDocumentList"></div>
<input id="0.28pl1tnk8h5-" name="openosp-image-link" value='{"id":"","value":"../eform/displayImage.do?imagefile=labreq3.png"}' type="hidden" />
</form>
<!doctype html>
<html lang="en">
<head>
<title>Form with Image</title>
</head>
<body>
<form action="../eform/addEForm.do?efmfid=91&efmdemographic_no=1&efmprovider_no=999998&eform_link=null" name="saveEForm" method="POST">
<img src="../eform/displayImage.do?imagefile=labreq3.png" alt="Sample Image">
</form>
</body>
</html>
To solve this issue, I have added the correct logic in the Why is this issue not occurring very often?
if (ConvertToEdoc.contextPath != null && ConvertToEdoc.realPath != null)
|





Status Quo
getRealPath()method does not correctly validate theuriparameter and is returning incorrect results.Changes
Fixed the
getRealPath()method based on the values ofConvertToEdoc.realPathandConvertToEdoc.contextPath.Current values:
ConvertToEdoc.realPath:/home/vagrant/tomcat/apache-tomcat-9.0.41/webapps/oscar/ConvertToEdoc.contextPath:/oscarBased on these values, it appears that
getRealPath()is intended to resolve the real path of the givenuriwithin theoscarproject directory. The implementation has been updated accordingly.