Skip to content
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

[DSD-4199] #329

Open
wants to merge 158 commits into
base: release-1.2.0.x
Choose a base branch
from
Open

[DSD-4199] #329

wants to merge 158 commits into from

Conversation

JanardhanBS-SyncByte
Copy link
Contributor

No description provided.

Prafulrakhade and others added 30 commits January 22, 2024 11:42
#325)

* [DSD-4267] removed mock-sdk-jpeg-extractor functionality from mosip-mock-services repo

Signed-off-by: techno-467 <[email protected]>

* [DSD-4267] removed mock-sdk-jpeg-extractor functionality from mosip-mock-services repo

Signed-off-by: techno-467 <[email protected]>

* [DSD-4267] removed mock-sdk-jpeg-extractor functionality from mosip-mock-services repo

Signed-off-by: techno-467 <[email protected]>

---------

Signed-off-by: techno-467 <[email protected]>
…e floating point numbers

Signed-off-by: JanardhanBS-SyncByte <[email protected]>
[MOSIP-31258] The attributes requestedScore and qualityScore should be floating point numbers
…e floating point numbers with return type String

Signed-off-by: JanardhanBS-SyncByte <[email protected]>
Signed-off-by: Sowmya Ujjappa Banakar <[email protected]>
Signed-off-by: JanardhanBS-SyncByte <[email protected]>
Signed-off-by: JanardhanBS-SyncByte <[email protected]>
Signed-off-by: JanardhanBS-SyncByte <[email protected]>
Signed-off-by: JanardhanBS-SyncByte <[email protected]>
Signed-off-by: JanardhanBS-SyncByte <[email protected]>
Signed-off-by: JanardhanBS-SyncByte <[email protected]>
Signed-off-by: JanardhanBS-SyncByte <[email protected]>
Signed-off-by: JanardhanBS-SyncByte <[email protected]>
…iometricsdk.version

Signed-off-by: JanardhanBS-SyncByte <[email protected]>
Signed-off-by: JanardhanBS-SyncByte <[email protected]>
Signed-off-by: JanardhanBS-SyncByte <[email protected]>
Signed-off-by: JanardhanBS-SyncByte <[email protected]>
Signed-off-by: JanardhanBS-SyncByte <[email protected]>
Signed-off-by: JanardhanBS-SyncByte <[email protected]>
Signed-off-by: JanardhanBS-SyncByte <[email protected]>
Signed-off-by: JanardhanBS-SyncByte <[email protected]>
Signed-off-by: JanardhanBS-SyncByte <[email protected]>
Signed-off-by: JanardhanBS-SyncByte <[email protected]>
Signed-off-by: JanardhanBS-SyncByte <[email protected]>
JanardhanBS-SyncByte and others added 28 commits July 9, 2024 16:00
[MOSIP-33587] Merge develop from develop-java21
Signed-off-by: Chandra Keshav Mishra <[email protected]>
[MOSIP-33587] Merge develop from develop-java21
Signed-off-by: GitHub <[email protected]>
Co-authored-by: Prafulrakhade <[email protected]>
Signed-off-by: JanardhanBS-SyncByte <[email protected]>
Signed-off-by: JanardhanBS-SyncByte <[email protected]>
Co-authored-by: JanardhanBS-SyncByte <[email protected]>
Signed-off-by: Praful Rakhade <[email protected]>
Signed-off-by: Praful Rakhade <[email protected]>
[MOSIP-35892] Updated helm charts to add range
Signed-off-by: JanardhanBS-SyncByte <[email protected]>
Signed-off-by: JanardhanBS-SyncByte <[email protected]>
Signed-off-by: JanardhanBS-SyncByte <[email protected]>
* Constructs the controller with the provided ProxyAbisConfigService instance.
*
* @param proxyAbisConfigService The service instance to be used by this
* controller.

Check warning

Code scanning / CodeQL

Cross-site scripting Medium

Cross-site scripting vulnerability due to a
user-provided value
.

Copilot Autofix AI 29 days ago

To fix the cross-site scripting vulnerability, we need to ensure that any user-provided data is properly sanitized or encoded before being included in the response. The best way to fix this issue is to use a library that provides HTML encoding to escape any potentially harmful characters.

In this case, we can use the StringEscapeUtils class from the Apache Commons Text library to encode the expectation.getId() value before including it in the response.

Suggested changeset 2
mock-abis/src/main/java/io/mosip/proxy/abis/controller/ProxyAbisConfigController.java

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/mock-abis/src/main/java/io/mosip/proxy/abis/controller/ProxyAbisConfigController.java b/mock-abis/src/main/java/io/mosip/proxy/abis/controller/ProxyAbisConfigController.java
--- a/mock-abis/src/main/java/io/mosip/proxy/abis/controller/ProxyAbisConfigController.java
+++ b/mock-abis/src/main/java/io/mosip/proxy/abis/controller/ProxyAbisConfigController.java
@@ -24,2 +24,3 @@
 import java.util.Map;
+import org.apache.commons.text.StringEscapeUtils;
 
@@ -70,3 +71,4 @@
 			proxyAbisConfigService.setExpectation(expectation);
-			return new ResponseEntity<>("Successfully inserted expectation " + expectation.getId(), HttpStatus.OK);
+			String safeExpectationId = StringEscapeUtils.escapeHtml4(expectation.getId());
+			return new ResponseEntity<>("Successfully inserted expectation " + safeExpectationId, HttpStatus.OK);
 		} catch (Exception exp) {
EOF
@@ -24,2 +24,3 @@
import java.util.Map;
import org.apache.commons.text.StringEscapeUtils;

@@ -70,3 +71,4 @@
proxyAbisConfigService.setExpectation(expectation);
return new ResponseEntity<>("Successfully inserted expectation " + expectation.getId(), HttpStatus.OK);
String safeExpectationId = StringEscapeUtils.escapeHtml4(expectation.getId());
return new ResponseEntity<>("Successfully inserted expectation " + safeExpectationId, HttpStatus.OK);
} catch (Exception exp) {
mock-abis/pom.xml
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/mock-abis/pom.xml b/mock-abis/pom.xml
--- a/mock-abis/pom.xml
+++ b/mock-abis/pom.xml
@@ -68,2 +68,7 @@
 	<dependencies>
+	<dependency>
+	<groupId>org.apache.commons</groupId>
+	<artifactId>commons-text</artifactId>
+	<version>1.12.0</version>
+	</dependency>
 		<dependency>
EOF
@@ -68,2 +68,7 @@
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.12.0</version>
</dependency>
<dependency>
This fix introduces these dependencies
Package Version Security advisories
org.apache.commons:commons-text (maven) 1.12.0 None
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
logger.info("Fetching CBEFF for reference URL-" + CBEFF_URL);
ResponseEntity<String> cbeffResp = restTemplate.exchange(CBEFF_URL, HttpMethod.GET, null, String.class);
logger.info("Fetching CBEFF for reference URL-" + cbeffURL);
ResponseEntity<String> cbeffResp = restTemplate.exchange(cbeffURL, HttpMethod.GET, null, String.class);

Check failure

Code scanning / CodeQL

Server-side request forgery Critical

Potential server-side request forgery due to a
user-provided value
.

Copilot Autofix AI 30 days ago

To fix the SSRF vulnerability, we need to ensure that the user-provided URL is validated against a list of authorized URLs or restricted to a particular host or URL prefix. This can be achieved by maintaining a list of valid URLs and checking the user input against this list before making the HTTP request.

  1. Create a list of authorized URLs.
  2. Validate the user-provided URL against this list.
  3. If the URL is not in the list, throw an exception or handle the error appropriately.
Suggested changeset 1
mock-abis/src/main/java/io/mosip/proxy/abis/service/impl/ProxyAbisInsertServiceImpl.java

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/mock-abis/src/main/java/io/mosip/proxy/abis/service/impl/ProxyAbisInsertServiceImpl.java b/mock-abis/src/main/java/io/mosip/proxy/abis/service/impl/ProxyAbisInsertServiceImpl.java
--- a/mock-abis/src/main/java/io/mosip/proxy/abis/service/impl/ProxyAbisInsertServiceImpl.java
+++ b/mock-abis/src/main/java/io/mosip/proxy/abis/service/impl/ProxyAbisInsertServiceImpl.java
@@ -1,2 +1,6 @@
-package io.mosip.proxy.abis.service.impl;
+package io.mosip.proxy.abis.service.impl;
+import java.util.Arrays;
+import java.util.List;
+import java.net.MalformedURLException;
+import java.net.URL;
 
@@ -134,3 +138,3 @@
 			}
-			cbeffURL = ire.getReferenceURL();
+			cbeffURL = validateURL(ire.getReferenceURL());
 			InsertEntity ie = new InsertEntity(ire.getId(), ire.getVersion(), ire.getRequestId(), ire.getRequesttime(),
@@ -166,3 +170,27 @@
 		}
-	}
+	}
+
+	/**
+	 * Validates the given URL against a list of authorized URLs.
+	 *
+	 * @param url the URL to validate
+	 * @return the validated URL if it is authorized
+	 * @throws RequestException if the URL is not authorized
+	 */
+	private String validateURL(String url) throws RequestException {
+		List<String> authorizedURLs = Arrays.asList(
+			"http://example.com/valid1",
+			"http://example.com/valid2"
+		);
+		try {
+			URL parsedURL = new URL(url);
+			if (authorizedURLs.contains(parsedURL.toString())) {
+				return url;
+			} else {
+				throw new RequestException(FailureReasonsConstants.UNAUTHORIZED_URL);
+			}
+		} catch (MalformedURLException e) {
+			throw new RequestException(FailureReasonsConstants.INVALID_URL_FORMAT);
+		}
+	}
 
EOF
@@ -1,2 +1,6 @@
package io.mosip.proxy.abis.service.impl;
package io.mosip.proxy.abis.service.impl;
import java.util.Arrays;
import java.util.List;
import java.net.MalformedURLException;
import java.net.URL;

@@ -134,3 +138,3 @@
}
cbeffURL = ire.getReferenceURL();
cbeffURL = validateURL(ire.getReferenceURL());
InsertEntity ie = new InsertEntity(ire.getId(), ire.getVersion(), ire.getRequestId(), ire.getRequesttime(),
@@ -166,3 +170,27 @@
}
}
}

/**
* Validates the given URL against a list of authorized URLs.
*
* @param url the URL to validate
* @return the validated URL if it is authorized
* @throws RequestException if the URL is not authorized
*/
private String validateURL(String url) throws RequestException {
List<String> authorizedURLs = Arrays.asList(
"http://example.com/valid1",
"http://example.com/valid2"
);
try {
URL parsedURL = new URL(url);
if (authorizedURLs.contains(parsedURL.toString())) {
return url;
} else {
throw new RequestException(FailureReasonsConstants.UNAUTHORIZED_URL);
}
} catch (MalformedURLException e) {
throw new RequestException(FailureReasonsConstants.INVALID_URL_FORMAT);
}
}

Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
@@ -312,28 +509,44 @@
return hexString.toString();
}

/**
* Finds potential duplicate biometric data based on the provided
* IdentityRequest.

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
This path depends on a
user-provided value
.

Copilot Autofix AI 30 days ago

To fix the problem, we need to validate the user-provided filename to ensure it does not contain any path traversal characters or sequences. This can be done by checking for the presence of "..", "/", or "\" in the filename. If any of these characters or sequences are found, we should reject the input.

The best way to fix the problem without changing existing functionality is to add a validation step before using the filename to construct the file path. This validation will ensure that the filename is safe to use.

Suggested changeset 1
mock-abis/src/main/java/io/mosip/proxy/abis/service/impl/ProxyAbisInsertServiceImpl.java

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/mock-abis/src/main/java/io/mosip/proxy/abis/service/impl/ProxyAbisInsertServiceImpl.java b/mock-abis/src/main/java/io/mosip/proxy/abis/service/impl/ProxyAbisInsertServiceImpl.java
--- a/mock-abis/src/main/java/io/mosip/proxy/abis/service/impl/ProxyAbisInsertServiceImpl.java
+++ b/mock-abis/src/main/java/io/mosip/proxy/abis/service/impl/ProxyAbisInsertServiceImpl.java
@@ -789,9 +789,13 @@
 			byte[] bytes = uploadedFile.getBytes();
-			Path path = Paths.get(keystoreFilePath.toString(), uploadedFile.getOriginalFilename());
-
-			File keyFile = new File(path.toString());
-			File parent = keyFile.getParentFile();
-			if (parent != null && !parent.exists() && !parent.mkdirs()) {
-				throw new IllegalStateException("Couldn't create dir: " + parent);
-			}
+			String originalFilename = uploadedFile.getOriginalFilename();
+			if (originalFilename.contains("..") || originalFilename.contains("/") || originalFilename.contains("\\")) {
+				throw new IllegalArgumentException("Invalid filename");
+			}
+			Path path = Paths.get(keystoreFilePath.toString(), originalFilename);
+
+			File keyFile = new File(path.toString());
+			File parent = keyFile.getParentFile();
+			if (parent != null && !parent.exists() && !parent.mkdirs()) {
+				throw new IllegalStateException("Couldn't create dir: " + parent);
+			}
 			boolean fileCreated = keyFile.createNewFile();
EOF
@@ -789,9 +789,13 @@
byte[] bytes = uploadedFile.getBytes();
Path path = Paths.get(keystoreFilePath.toString(), uploadedFile.getOriginalFilename());

File keyFile = new File(path.toString());
File parent = keyFile.getParentFile();
if (parent != null && !parent.exists() && !parent.mkdirs()) {
throw new IllegalStateException("Couldn't create dir: " + parent);
}
String originalFilename = uploadedFile.getOriginalFilename();
if (originalFilename.contains("..") || originalFilename.contains("/") || originalFilename.contains("\\")) {
throw new IllegalArgumentException("Invalid filename");
}
Path path = Paths.get(keystoreFilePath.toString(), originalFilename);

File keyFile = new File(path.toString());
File parent = keyFile.getParentFile();
if (parent != null && !parent.exists() && !parent.mkdirs()) {
throw new IllegalStateException("Couldn't create dir: " + parent);
}
boolean fileCreated = keyFile.createNewFile();
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
@@ -312,28 +509,44 @@
return hexString.toString();
}

/**
* Finds potential duplicate biometric data based on the provided
* IdentityRequest.

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
This path depends on a
user-provided value
.

Copilot Autofix AI 30 days ago

To fix the problem, we need to validate the user-provided filename to ensure it does not contain any path traversal sequences or invalid characters. We can achieve this by checking for the presence of "..", "/", and "\" in the filename and rejecting the input if any of these are found. Additionally, we should ensure that the filename is a single path component and does not contain any directory separators.

Steps to fix:

  1. Validate the uploadedFile.getOriginalFilename() to ensure it does not contain any path traversal sequences or invalid characters.
  2. Reject the input if the validation fails and throw an appropriate exception.
Suggested changeset 1
mock-abis/src/main/java/io/mosip/proxy/abis/service/impl/ProxyAbisInsertServiceImpl.java

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/mock-abis/src/main/java/io/mosip/proxy/abis/service/impl/ProxyAbisInsertServiceImpl.java b/mock-abis/src/main/java/io/mosip/proxy/abis/service/impl/ProxyAbisInsertServiceImpl.java
--- a/mock-abis/src/main/java/io/mosip/proxy/abis/service/impl/ProxyAbisInsertServiceImpl.java
+++ b/mock-abis/src/main/java/io/mosip/proxy/abis/service/impl/ProxyAbisInsertServiceImpl.java
@@ -789,9 +789,13 @@
 			byte[] bytes = uploadedFile.getBytes();
-			Path path = Paths.get(keystoreFilePath.toString(), uploadedFile.getOriginalFilename());
-
-			File keyFile = new File(path.toString());
-			File parent = keyFile.getParentFile();
-			if (parent != null && !parent.exists() && !parent.mkdirs()) {
-				throw new IllegalStateException("Couldn't create dir: " + parent);
-			}
+			String originalFilename = uploadedFile.getOriginalFilename();
+			if (originalFilename.contains("..") || originalFilename.contains("/") || originalFilename.contains("\\")) {
+				throw new IllegalArgumentException("Invalid filename");
+			}
+			Path path = Paths.get(keystoreFilePath.toString(), originalFilename);
+
+			File keyFile = new File(path.toString());
+			File parent = keyFile.getParentFile();
+			if (parent != null && !parent.exists() && !parent.mkdirs()) {
+				throw new IllegalStateException("Couldn't create dir: " + parent);
+			}
 			boolean fileCreated = keyFile.createNewFile();
EOF
@@ -789,9 +789,13 @@
byte[] bytes = uploadedFile.getBytes();
Path path = Paths.get(keystoreFilePath.toString(), uploadedFile.getOriginalFilename());

File keyFile = new File(path.toString());
File parent = keyFile.getParentFile();
if (parent != null && !parent.exists() && !parent.mkdirs()) {
throw new IllegalStateException("Couldn't create dir: " + parent);
}
String originalFilename = uploadedFile.getOriginalFilename();
if (originalFilename.contains("..") || originalFilename.contains("/") || originalFilename.contains("\\")) {
throw new IllegalArgumentException("Invalid filename");
}
Path path = Paths.get(keystoreFilePath.toString(), originalFilename);

File keyFile = new File(path.toString());
File parent = keyFile.getParentFile();
if (parent != null && !parent.exists() && !parent.mkdirs()) {
throw new IllegalStateException("Couldn't create dir: " + parent);
}
boolean fileCreated = keyFile.createNewFile();
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
@@ -514,33 +794,32 @@
if (parent != null && !parent.exists() && !parent.mkdirs()) {
throw new IllegalStateException("Couldn't create dir: " + parent);
}
keyFile.createNewFile();
boolean fileCreated = keyFile.createNewFile();

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
This path depends on a
user-provided value
.

Copilot Autofix AI 30 days ago

To fix the problem, we need to validate the filename obtained from uploadedFile.getOriginalFilename() to ensure it does not contain any path separators or parent directory references. This can be done by checking for the presence of characters like /, \, or .. in the filename. If any of these characters are found, we should reject the input and throw an exception.

Suggested changeset 1
mock-abis/src/main/java/io/mosip/proxy/abis/service/impl/ProxyAbisInsertServiceImpl.java

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/mock-abis/src/main/java/io/mosip/proxy/abis/service/impl/ProxyAbisInsertServiceImpl.java b/mock-abis/src/main/java/io/mosip/proxy/abis/service/impl/ProxyAbisInsertServiceImpl.java
--- a/mock-abis/src/main/java/io/mosip/proxy/abis/service/impl/ProxyAbisInsertServiceImpl.java
+++ b/mock-abis/src/main/java/io/mosip/proxy/abis/service/impl/ProxyAbisInsertServiceImpl.java
@@ -789,11 +789,15 @@
 			byte[] bytes = uploadedFile.getBytes();
-			Path path = Paths.get(keystoreFilePath.toString(), uploadedFile.getOriginalFilename());
-
-			File keyFile = new File(path.toString());
-			File parent = keyFile.getParentFile();
-			if (parent != null && !parent.exists() && !parent.mkdirs()) {
-				throw new IllegalStateException("Couldn't create dir: " + parent);
-			}
-			boolean fileCreated = keyFile.createNewFile();
-			Files.write(path, bytes);
+			String originalFilename = uploadedFile.getOriginalFilename();
+			if (originalFilename.contains("..") || originalFilename.contains("/") || originalFilename.contains("\\")) {
+				throw new IllegalArgumentException("Invalid filename");
+			}
+			Path path = Paths.get(keystoreFilePath.toString(), originalFilename);
+
+			File keyFile = new File(path.toString());
+			File parent = keyFile.getParentFile();
+			if (parent != null && !parent.exists() && !parent.mkdirs()) {
+				throw new IllegalStateException("Couldn't create dir: " + parent);
+			}
+			boolean fileCreated = keyFile.createNewFile();
+			Files.write(path, bytes);
 
EOF
@@ -789,11 +789,15 @@
byte[] bytes = uploadedFile.getBytes();
Path path = Paths.get(keystoreFilePath.toString(), uploadedFile.getOriginalFilename());

File keyFile = new File(path.toString());
File parent = keyFile.getParentFile();
if (parent != null && !parent.exists() && !parent.mkdirs()) {
throw new IllegalStateException("Couldn't create dir: " + parent);
}
boolean fileCreated = keyFile.createNewFile();
Files.write(path, bytes);
String originalFilename = uploadedFile.getOriginalFilename();
if (originalFilename.contains("..") || originalFilename.contains("/") || originalFilename.contains("\\")) {
throw new IllegalArgumentException("Invalid filename");
}
Path path = Paths.get(keystoreFilePath.toString(), originalFilename);

File keyFile = new File(path.toString());
File parent = keyFile.getParentFile();
if (parent != null && !parent.exists() && !parent.mkdirs()) {
throw new IllegalStateException("Couldn't create dir: " + parent);
}
boolean fileCreated = keyFile.createNewFile();
Files.write(path, bytes);

Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
} catch (RuntimeException exp) {
logger.error(String.format("Exception while getting expectation: %s",request));
throw exp;
return new ResponseEntity<>("Successfully inserted expectation " + expectation.getRId(), HttpStatus.OK);

Check warning

Code scanning / CodeQL

Cross-site scripting Medium

Cross-site scripting vulnerability due to a
user-provided value
.

Copilot Autofix AI 30 days ago

To fix the problem, we need to ensure that any user-provided data included in the HTTP response is properly sanitized or encoded to prevent XSS attacks. In this case, we can use the HtmlUtils.htmlEscape method from the org.springframework.web.util package to escape the expectation.getRId() value before including it in the response.

Suggested changeset 1
mock-mv/src/main/java/io/mosip/mock/mv/controller/MockMvConfigController.java

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/mock-mv/src/main/java/io/mosip/mock/mv/controller/MockMvConfigController.java b/mock-mv/src/main/java/io/mosip/mock/mv/controller/MockMvConfigController.java
--- a/mock-mv/src/main/java/io/mosip/mock/mv/controller/MockMvConfigController.java
+++ b/mock-mv/src/main/java/io/mosip/mock/mv/controller/MockMvConfigController.java
@@ -1,2 +1,3 @@
 package io.mosip.mock.mv.controller;
+import org.springframework.web.util.HtmlUtils;
 
@@ -136,3 +137,4 @@
 			mockMvDecisionService.setExpectation(expectation);
-			return new ResponseEntity<>("Successfully inserted expectation " + expectation.getRId(), HttpStatus.OK);
+			String escapedRId = HtmlUtils.htmlEscape(expectation.getRId());
+			return new ResponseEntity<>("Successfully inserted expectation " + escapedRId, HttpStatus.OK);
 		} catch (Exception exp) {
EOF
@@ -1,2 +1,3 @@
package io.mosip.mock.mv.controller;
import org.springframework.web.util.HtmlUtils;

@@ -136,3 +137,4 @@
mockMvDecisionService.setExpectation(expectation);
return new ResponseEntity<>("Successfully inserted expectation " + expectation.getRId(), HttpStatus.OK);
String escapedRId = HtmlUtils.htmlEscape(expectation.getRId());
return new ResponseEntity<>("Successfully inserted expectation " + escapedRId, HttpStatus.OK);
} catch (Exception exp) {
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
if (expectation.getRId() != null)
return new ResponseEntity<>(mockMvDecisionService.getExpectation(rid).toString(), HttpStatus.OK);
else {
return new ResponseEntity<>("No expectation set for given rid:" + rid, HttpStatus.OK);

Check warning

Code scanning / CodeQL

Cross-site scripting Medium

Cross-site scripting vulnerability due to a
user-provided value
.

Copilot Autofix AI 29 days ago

To fix the cross-site scripting vulnerability, we need to ensure that any user-provided input is properly sanitized or encoded before being included in the response. In this case, we can use the StringEscapeUtils class from the Apache Commons Text library to escape the rid parameter before including it in the response.

  1. Add the necessary import for StringEscapeUtils.
  2. Escape the rid parameter before including it in the response.
Suggested changeset 2
mock-mv/src/main/java/io/mosip/mock/mv/controller/MockMvConfigController.java

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/mock-mv/src/main/java/io/mosip/mock/mv/controller/MockMvConfigController.java b/mock-mv/src/main/java/io/mosip/mock/mv/controller/MockMvConfigController.java
--- a/mock-mv/src/main/java/io/mosip/mock/mv/controller/MockMvConfigController.java
+++ b/mock-mv/src/main/java/io/mosip/mock/mv/controller/MockMvConfigController.java
@@ -32,2 +32,3 @@
 import jakarta.validation.Valid;
+import org.apache.commons.text.StringEscapeUtils;
 
@@ -184,3 +185,3 @@
 			else {
-				return new ResponseEntity<>("No expectation set for given rid:" + rid, HttpStatus.OK);
+				return new ResponseEntity<>("No expectation set for given rid:" + StringEscapeUtils.escapeHtml4(rid), HttpStatus.OK);
 			}
EOF
@@ -32,2 +32,3 @@
import jakarta.validation.Valid;
import org.apache.commons.text.StringEscapeUtils;

@@ -184,3 +185,3 @@
else {
return new ResponseEntity<>("No expectation set for given rid:" + rid, HttpStatus.OK);
return new ResponseEntity<>("No expectation set for given rid:" + StringEscapeUtils.escapeHtml4(rid), HttpStatus.OK);
}
mock-mv/pom.xml
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/mock-mv/pom.xml b/mock-mv/pom.xml
--- a/mock-mv/pom.xml
+++ b/mock-mv/pom.xml
@@ -69,2 +69,7 @@
 	<dependencies>
+	<dependency>
+	<groupId>org.apache.commons</groupId>
+	<artifactId>commons-text</artifactId>
+	<version>1.12.0</version>
+	</dependency>
 		<dependency>
EOF
@@ -69,2 +69,7 @@
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.12.0</version>
</dependency>
<dependency>
This fix introduces these dependencies
Package Version Security advisories
org.apache.commons:commons-text (maven) 1.12.0 None
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
logger.info("Delete expectation: {}", rid);
try {
mockMvDecisionService.deleteExpectation(rid);
return new ResponseEntity<>("Successfully deleted expectation " + rid, HttpStatus.OK);

Check warning

Code scanning / CodeQL

Cross-site scripting Medium

Cross-site scripting vulnerability due to a
user-provided value
.

Copilot Autofix AI 29 days ago

To fix the cross-site scripting vulnerability, we need to ensure that any user-provided input is properly sanitized or encoded before being included in the response. In this case, we can use the HtmlUtils.htmlEscape method from the org.springframework.web.util package to escape the rid parameter before including it in the response.

Suggested changeset 1
mock-mv/src/main/java/io/mosip/mock/mv/controller/MockMvConfigController.java

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/mock-mv/src/main/java/io/mosip/mock/mv/controller/MockMvConfigController.java b/mock-mv/src/main/java/io/mosip/mock/mv/controller/MockMvConfigController.java
--- a/mock-mv/src/main/java/io/mosip/mock/mv/controller/MockMvConfigController.java
+++ b/mock-mv/src/main/java/io/mosip/mock/mv/controller/MockMvConfigController.java
@@ -1,2 +1,3 @@
 package io.mosip.mock.mv.controller;
+import org.springframework.web.util.HtmlUtils;
 
@@ -213,3 +214,3 @@
 			mockMvDecisionService.deleteExpectation(rid);
-			return new ResponseEntity<>("Successfully deleted expectation " + rid, HttpStatus.OK);
+			return new ResponseEntity<>("Successfully deleted expectation " + HtmlUtils.htmlEscape(rid), HttpStatus.OK);
 		} catch (Exception exp) {
EOF
@@ -1,2 +1,3 @@
package io.mosip.mock.mv.controller;
import org.springframework.web.util.HtmlUtils;

@@ -213,3 +214,3 @@
mockMvDecisionService.deleteExpectation(rid);
return new ResponseEntity<>("Successfully deleted expectation " + rid, HttpStatus.OK);
return new ResponseEntity<>("Successfully deleted expectation " + HtmlUtils.htmlEscape(rid), HttpStatus.OK);
} catch (Exception exp) {
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
* [MOSIP-37853]added skip for deployment in pom

Signed-off-by: JanardhanBS-SyncByte <[email protected]>

* [MOSIP-37853]added skip for deployment in pom

Signed-off-by: JanardhanBS-SyncByte <[email protected]>

---------

Signed-off-by: JanardhanBS-SyncByte <[email protected]>
Co-authored-by: JanardhanBS-SyncByte <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.