Skip to content

Format and cleanup java source #705

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Mar 31, 2025
Merged

Format and cleanup java source #705

merged 1 commit into from
Mar 31, 2025

Conversation

ivy-cst
Copy link
Member

@ivy-cst ivy-cst commented Mar 31, 2025

No description provided.

Comment on lines 155 to +157
return Response.status(Status.NOT_FOUND)
.entity("user with id '" + personId + "' does not exist.")
.build();
.entity("user with id '" + personId + "' does not exist.")
.build();

Check warning

Code scanning / CodeQL

Cross-site scripting Medium

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

Copilot Autofix

AI 17 days ago

To fix the cross-site scripting vulnerability, we need to ensure that any user-provided data included in the response is properly sanitized or encoded. In this case, we can use the StringEscapeUtils.escapeHtml4 method from the Apache Commons Lang library to escape any HTML characters in the personId before including it in the response message.

Suggested changeset 1
connectivity/connectivity-demos/src/com/axonivy/connectivity/rest/provider/PersonService.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/connectivity/connectivity-demos/src/com/axonivy/connectivity/rest/provider/PersonService.java b/connectivity/connectivity-demos/src/com/axonivy/connectivity/rest/provider/PersonService.java
--- a/connectivity/connectivity-demos/src/com/axonivy/connectivity/rest/provider/PersonService.java
+++ b/connectivity/connectivity-demos/src/com/axonivy/connectivity/rest/provider/PersonService.java
@@ -27,2 +27,3 @@
 import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.text.StringEscapeUtils;
 
@@ -154,4 +155,5 @@
     } catch (IndexOutOfBoundsException ex) {
+      String safePersonId = StringEscapeUtils.escapeHtml4(personId.toString());
       return Response.status(Status.NOT_FOUND)
-          .entity("user with id '" + personId + "' does not exist.")
+          .entity("user with id '" + safePersonId + "' does not exist.")
           .build();
EOF
@@ -27,2 +27,3 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringEscapeUtils;

@@ -154,4 +155,5 @@
} catch (IndexOutOfBoundsException ex) {
String safePersonId = StringEscapeUtils.escapeHtml4(personId.toString());
return Response.status(Status.NOT_FOUND)
.entity("user with id '" + personId + "' does not exist.")
.entity("user with id '" + safePersonId + "' does not exist.")
.build();
Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines 77 to +79
return Response.status(Status.OK)
.entity("Added entry '" + newEntry + "'")
.build();
.entity("Added entry '" + newEntry + "'")
.build();

Check warning

Code scanning / CodeQL

Cross-site scripting Medium

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

Copilot Autofix

AI 17 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. The best way to fix this issue is to use a library that provides HTML encoding to escape any potentially harmful characters in the user input.

In this case, we can use the StringEscapeUtils class from the Apache Commons Text library to encode the newEntry parameter before including it in the response.

Suggested changeset 2
connectivity/connectivity-demos/src/com/axonivy/connectivity/rest/provider/SecureService.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/connectivity/connectivity-demos/src/com/axonivy/connectivity/rest/provider/SecureService.java b/connectivity/connectivity-demos/src/com/axonivy/connectivity/rest/provider/SecureService.java
--- a/connectivity/connectivity-demos/src/com/axonivy/connectivity/rest/provider/SecureService.java
+++ b/connectivity/connectivity-demos/src/com/axonivy/connectivity/rest/provider/SecureService.java
@@ -5,3 +5,3 @@
 import java.util.List;
-
+import org.apache.commons.text.StringEscapeUtils;
 import javax.annotation.security.DenyAll;
@@ -76,4 +76,5 @@
     entries.add(newEntry);
+    String encodedEntry = StringEscapeUtils.escapeHtml4(newEntry);
     return Response.status(Status.OK)
-        .entity("Added entry '" + newEntry + "'")
+        .entity("Added entry '" + encodedEntry + "'")
         .build();
EOF
@@ -5,3 +5,3 @@
import java.util.List;

import org.apache.commons.text.StringEscapeUtils;
import javax.annotation.security.DenyAll;
@@ -76,4 +76,5 @@
entries.add(newEntry);
String encodedEntry = StringEscapeUtils.escapeHtml4(newEntry);
return Response.status(Status.OK)
.entity("Added entry '" + newEntry + "'")
.entity("Added entry '" + encodedEntry + "'")
.build();
connectivity/connectivity-demos/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/connectivity/connectivity-demos/pom.xml b/connectivity/connectivity-demos/pom.xml
--- a/connectivity/connectivity-demos/pom.xml
+++ b/connectivity/connectivity-demos/pom.xml
@@ -1,2 +1,9 @@
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-text</artifactId>
+            <version>1.13.0</version>
+        </dependency>
+    </dependencies>
   <modelVersion>4.0.0</modelVersion>
EOF
@@ -1,2 +1,9 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.13.0</version>
</dependency>
</dependencies>
<modelVersion>4.0.0</modelVersion>
This fix introduces these dependencies
Package Version Security advisories
org.apache.commons:commons-text (maven) 1.13.0 None
Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines 91 to +93
return Response.status(Status.OK)
.entity("Update entry with id (" + id + ") to '" + newEntry + "'")
.build();
.entity("Update entry with id (" + id + ") to '" + newEntry + "'")
.build();

Check warning

Code scanning / CodeQL

Cross-site scripting Medium

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

Copilot Autofix

AI 17 days ago

To fix the cross-site scripting vulnerability, we need to sanitize or encode the user-provided input before including it in the response. The best way to fix this issue is to use a library that provides HTML encoding to ensure that any potentially malicious scripts are rendered harmless.

In this case, we can use the StringEscapeUtils class from the Apache Commons Text library to encode the newEntry parameter before including it in the response.

Suggested changeset 2
connectivity/connectivity-demos/src/com/axonivy/connectivity/rest/provider/SecureService.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/connectivity/connectivity-demos/src/com/axonivy/connectivity/rest/provider/SecureService.java b/connectivity/connectivity-demos/src/com/axonivy/connectivity/rest/provider/SecureService.java
--- a/connectivity/connectivity-demos/src/com/axonivy/connectivity/rest/provider/SecureService.java
+++ b/connectivity/connectivity-demos/src/com/axonivy/connectivity/rest/provider/SecureService.java
@@ -23,2 +23,3 @@
 import io.swagger.v3.oas.annotations.tags.Tag;
+import org.apache.commons.text.StringEscapeUtils;
 
@@ -90,4 +91,5 @@
     entries.set(id, newEntry);
+    String encodedEntry = StringEscapeUtils.escapeHtml4(newEntry);
     return Response.status(Status.OK)
-        .entity("Update entry with id (" + id + ") to '" + newEntry + "'")
+        .entity("Update entry with id (" + id + ") to '" + encodedEntry + "'")
         .build();
EOF
@@ -23,2 +23,3 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.text.StringEscapeUtils;

@@ -90,4 +91,5 @@
entries.set(id, newEntry);
String encodedEntry = StringEscapeUtils.escapeHtml4(newEntry);
return Response.status(Status.OK)
.entity("Update entry with id (" + id + ") to '" + newEntry + "'")
.entity("Update entry with id (" + id + ") to '" + encodedEntry + "'")
.build();
connectivity/connectivity-demos/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/connectivity/connectivity-demos/pom.xml b/connectivity/connectivity-demos/pom.xml
--- a/connectivity/connectivity-demos/pom.xml
+++ b/connectivity/connectivity-demos/pom.xml
@@ -1,2 +1,9 @@
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-text</artifactId>
+            <version>1.13.0</version>
+        </dependency>
+    </dependencies>
   <modelVersion>4.0.0</modelVersion>
EOF
@@ -1,2 +1,9 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.13.0</version>
</dependency>
</dependencies>
<modelVersion>4.0.0</modelVersion>
This fix introduces these dependencies
Package Version Security advisories
org.apache.commons:commons-text (maven) 1.13.0 None
Copilot is powered by AI and may make mistakes. Always verify output.
@ivy-cst ivy-cst merged commit dabe13a into master Mar 31, 2025
10 checks passed
@ivy-cst ivy-cst deleted the format-java branch March 31, 2025 13:23
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants