forked from Raxa/raxacore
-
Notifications
You must be signed in to change notification settings - Fork 269
BAH-4991 Remediate Security Findings in Bahmni-core #344
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
Open
lingeswaranTW
wants to merge
9
commits into
master
Choose a base branch
from
BAH-4991
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a0a08dd
Path traversal to arbitrary Groovy execution via the flowSheet
lingeswaranTW 9a8a3ac
BAH-4971 SQL injection via concatenated into a native REGEXP literal
lingeswaranTW 4f2ad3f
F03 Path traversal to arbitrary Groovy execution via the import patie…
lingeswaranTW 29337ae
F04 Path-traversal file read and IDOR on the patient image endpoint
lingeswaranTW 0eeb5a6
F07 Groovy class loaded from an encounter-modifier concept-set name
lingeswaranTW 61082ec
F08 Missing authorization on the import-status endpoint
lingeswaranTW 241dae0
F09 Do not start fix first try to reproduce then i will try by myself…
lingeswaranTW bae85bd
BAH-4971 Reverting patient image v2 endpoint which deleted
lingeswaranTW dc728cc
BAH-4991 Code review changes
lingeswaranTW File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
admin/src/test/java/org/bahmni/module/admin/csv/service/PatientMatchServiceTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| package org.bahmni.module.admin.csv.service; | ||
|
|
||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
| import org.junit.rules.ExpectedException; | ||
| import org.junit.rules.TemporaryFolder; | ||
|
|
||
| import java.io.File; | ||
| import java.lang.reflect.InvocationTargetException; | ||
| import java.lang.reflect.Method; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
|
|
||
| public class PatientMatchServiceTest { | ||
|
|
||
| private static final String APP_DATA_DIR_PROPERTY = "OPENMRS_APPLICATION_DATA_DIRECTORY"; | ||
| private static final String ALGORITHM_DIR_NAME = "patientMatchingAlgorithm"; | ||
|
|
||
| @Rule | ||
| public TemporaryFolder appDataDir = new TemporaryFolder(); | ||
|
|
||
| @Rule | ||
| public ExpectedException expectedEx = ExpectedException.none(); | ||
|
|
||
| private String originalAppDataDirProperty; | ||
| private Method getAlgorithmClassPath; | ||
|
|
||
| @Before | ||
| public void setUp() throws Exception { | ||
| originalAppDataDirProperty = System.getProperty(APP_DATA_DIR_PROPERTY); | ||
| System.setProperty(APP_DATA_DIR_PROPERTY, appDataDir.getRoot().getAbsolutePath()); | ||
| appDataDir.newFolder(ALGORITHM_DIR_NAME); | ||
|
|
||
| getAlgorithmClassPath = PatientMatchService.class.getDeclaredMethod("getAlgorithmClassPath", String.class); | ||
| getAlgorithmClassPath.setAccessible(true); | ||
| } | ||
|
|
||
| @After | ||
| public void tearDown() { | ||
| if (originalAppDataDirProperty == null) { | ||
| System.clearProperty(APP_DATA_DIR_PROPERTY); | ||
| } else { | ||
| System.setProperty(APP_DATA_DIR_PROPERTY, originalAppDataDirProperty); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldResolveASimpleNameInsideTheAlgorithmDirectory() throws Exception { | ||
| String resolvedPath = invoke("SimpleAlgorithm.groovy"); | ||
| String expectedPath = new File(new File(appDataDir.getRoot(), ALGORITHM_DIR_NAME), "SimpleAlgorithm.groovy").getPath(); | ||
| assertEquals(expectedPath, resolvedPath); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldRejectRelativePathTraversalOutsideTheAlgorithmDirectory() throws Exception { | ||
| expectedEx.expect(IllegalArgumentException.class); | ||
| expectedEx.expectMessage("Invalid patientMatchingAlgorithm"); | ||
| invoke("../../../../tmp/evil/Pwn.groovy"); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldRejectAbsolutePathPayload() throws Exception { | ||
| expectedEx.expect(IllegalArgumentException.class); | ||
| expectedEx.expectMessage("Invalid patientMatchingAlgorithm"); | ||
| invoke("/etc/passwd"); | ||
| } | ||
|
|
||
| private String invoke(String matchingAlgorithmClassName) throws Exception { | ||
| try { | ||
| return (String) getAlgorithmClassPath.invoke(new PatientMatchService(), matchingAlgorithmClassName); | ||
| } catch (InvocationTargetException e) { | ||
| if (e.getCause() instanceof RuntimeException) { | ||
| throw (RuntimeException) e.getCause(); | ||
| } | ||
| throw e; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: Bahmni/bahmni-core
Length of output: 435
🏁 Script executed:
Repository: Bahmni/bahmni-core
Length of output: 50374
🏁 Script executed:
Repository: Bahmni/bahmni-core
Length of output: 4588
🏁 Script executed:
Repository: Bahmni/bahmni-core
Length of output: 3396
Sanitize
originalFileNamebefore constructing the relative path.PatientDocumentService.saveDocumentacceptsfileNamedirectly, andPatientDocumentServiceImpl.createFileNameappends it without sanitization. Traversal segments can resolve the generated path to another document insidebasePath; the containment check accepts that path, andFileUtils.writeByteArrayToFilecan overwrite the existing document. SanitizeoriginalFileNamein the service before appending it.🤖 Prompt for AI Agents