Skip to content

Conversation

@vinokurig
Copy link
Contributor

@Path("/oidcCallbackIde.html")
@Produces("text/html")
public String ideCallback() throws IOException {
return getKeycloakResource("oidcCallbackIde.html");

Check warning

Code scanning / CodeQL

Cross-site scripting Medium

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

Copilot Autofix

AI 8 months ago

To fix the issue, the content of the file read by getKeycloakResource should be sanitized or escaped before being returned in the HTTP response. Since the content is served as HTML, it is appropriate to use an HTML escaping library to ensure that any potentially malicious content is neutralized. The StringEscapeUtils.escapeHtml4 method from Apache Commons Text is a reliable choice for this purpose.

The fix involves:

  1. Adding the Apache Commons Text library to the project dependencies (if not already present).
  2. Escaping the content returned by getKeycloakResource in the ideCallback method before returning it.

Suggested changeset 2
multiuser/keycloak/che-multiuser-keycloak-server/src/main/java/org/eclipse/che/multiuser/keycloak/server/KeycloakConfigurationService.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/multiuser/keycloak/che-multiuser-keycloak-server/src/main/java/org/eclipse/che/multiuser/keycloak/server/KeycloakConfigurationService.java b/multiuser/keycloak/che-multiuser-keycloak-server/src/main/java/org/eclipse/che/multiuser/keycloak/server/KeycloakConfigurationService.java
--- a/multiuser/keycloak/che-multiuser-keycloak-server/src/main/java/org/eclipse/che/multiuser/keycloak/server/KeycloakConfigurationService.java
+++ b/multiuser/keycloak/che-multiuser-keycloak-server/src/main/java/org/eclipse/che/multiuser/keycloak/server/KeycloakConfigurationService.java
@@ -24,2 +24,3 @@
 import java.util.Map;
+import org.apache.commons.text.StringEscapeUtils;
 import javax.inject.Inject;
@@ -88,3 +89,3 @@
   public String ideCallback() throws IOException {
-    return getKeycloakResource("oidcCallbackIde.html");
+    return org.apache.commons.text.StringEscapeUtils.escapeHtml4(getKeycloakResource("oidcCallbackIde.html"));
   }
EOF
@@ -24,2 +24,3 @@
import java.util.Map;
import org.apache.commons.text.StringEscapeUtils;
import javax.inject.Inject;
@@ -88,3 +89,3 @@
public String ideCallback() throws IOException {
return getKeycloakResource("oidcCallbackIde.html");
return org.apache.commons.text.StringEscapeUtils.escapeHtml4(getKeycloakResource("oidcCallbackIde.html"));
}
multiuser/keycloak/che-multiuser-keycloak-server/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/multiuser/keycloak/che-multiuser-keycloak-server/pom.xml b/multiuser/keycloak/che-multiuser-keycloak-server/pom.xml
--- a/multiuser/keycloak/che-multiuser-keycloak-server/pom.xml
+++ b/multiuser/keycloak/che-multiuser-keycloak-server/pom.xml
@@ -29,2 +29,7 @@
         <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-text</artifactId>
+            <version>1.13.1</version>
+        </dependency>
+        <dependency>
             <groupId>com.auth0</groupId>
EOF
@@ -29,2 +29,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.13.1</version>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
This fix introduces these dependencies
Package Version Security advisories
org.apache.commons:commons-text (maven) 1.13.1 None
Copilot is powered by AI and may make mistakes. Always verify output.
@Path("/oidcCallbackDashboard.html")
@Produces("text/html")
public String dashboardCallback() throws IOException {
return getKeycloakResource("oidcCallbackDashboard.html");

Check warning

Code scanning / CodeQL

Cross-site scripting Medium

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

Copilot Autofix

AI 8 months ago

To fix the issue, the content of the file should be sanitized or encoded before being returned in the HTTP response. Since the file is served as HTML, we can use an HTML encoding library to ensure that any potentially malicious content is safely escaped. This will prevent the execution of any embedded scripts or malicious HTML.

The best way to implement this fix is to use a well-known library like Apache Commons Text's StringEscapeUtils to encode the content as HTML. This ensures that any special characters in the file content are properly escaped.

Suggested changeset 2
multiuser/keycloak/che-multiuser-keycloak-server/src/main/java/org/eclipse/che/multiuser/keycloak/server/KeycloakConfigurationService.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/multiuser/keycloak/che-multiuser-keycloak-server/src/main/java/org/eclipse/che/multiuser/keycloak/server/KeycloakConfigurationService.java b/multiuser/keycloak/che-multiuser-keycloak-server/src/main/java/org/eclipse/che/multiuser/keycloak/server/KeycloakConfigurationService.java
--- a/multiuser/keycloak/che-multiuser-keycloak-server/src/main/java/org/eclipse/che/multiuser/keycloak/server/KeycloakConfigurationService.java
+++ b/multiuser/keycloak/che-multiuser-keycloak-server/src/main/java/org/eclipse/che/multiuser/keycloak/server/KeycloakConfigurationService.java
@@ -22,2 +22,3 @@
 import java.net.URL;
+import org.apache.commons.text.StringEscapeUtils;
 import java.net.URLConnection;
@@ -95,3 +96,3 @@
   public String dashboardCallback() throws IOException {
-    return getKeycloakResource("oidcCallbackDashboard.html");
+    return org.apache.commons.text.StringEscapeUtils.escapeHtml4(getKeycloakResource("oidcCallbackDashboard.html"));
   }
EOF
@@ -22,2 +22,3 @@
import java.net.URL;
import org.apache.commons.text.StringEscapeUtils;
import java.net.URLConnection;
@@ -95,3 +96,3 @@
public String dashboardCallback() throws IOException {
return getKeycloakResource("oidcCallbackDashboard.html");
return org.apache.commons.text.StringEscapeUtils.escapeHtml4(getKeycloakResource("oidcCallbackDashboard.html"));
}
multiuser/keycloak/che-multiuser-keycloak-server/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/multiuser/keycloak/che-multiuser-keycloak-server/pom.xml b/multiuser/keycloak/che-multiuser-keycloak-server/pom.xml
--- a/multiuser/keycloak/che-multiuser-keycloak-server/pom.xml
+++ b/multiuser/keycloak/che-multiuser-keycloak-server/pom.xml
@@ -29,2 +29,7 @@
         <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-text</artifactId>
+            <version>1.13.1</version>
+        </dependency>
+        <dependency>
             <groupId>com.auth0</groupId>
EOF
@@ -29,2 +29,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.13.1</version>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
This fix introduces these dependencies
Package Version Security advisories
org.apache.commons:commons-text (maven) 1.13.1 None
Copilot is powered by AI and may make mistakes. Always verify output.
}
url = ub.build().toString();
}
final HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();

Check failure

Code scanning / CodeQL

Server-side request forgery Critical

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

Copilot Autofix

AI 8 months ago

To fix the SSRF vulnerability, we need to validate the oauthProvider parameter against a predefined list of allowed values. This ensures that only trusted and expected values are used to construct the URL. The validation should occur as early as possible, ideally in the getIdentityProviderToken method of KeycloakServiceClient.java.

Steps to implement the fix:

  1. Define a list of allowed oauthProvider values (e.g., in a configuration file or as a constant in the class).
  2. Validate the oauthProvider parameter against this list before using it to construct the URL.
  3. If the validation fails, throw an appropriate exception (e.g., BadRequestException).

Suggested changeset 1
multiuser/keycloak/che-multiuser-keycloak-server/src/main/java/org/eclipse/che/multiuser/keycloak/server/KeycloakServiceClient.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/multiuser/keycloak/che-multiuser-keycloak-server/src/main/java/org/eclipse/che/multiuser/keycloak/server/KeycloakServiceClient.java b/multiuser/keycloak/che-multiuser-keycloak-server/src/main/java/org/eclipse/che/multiuser/keycloak/server/KeycloakServiceClient.java
--- a/multiuser/keycloak/che-multiuser-keycloak-server/src/main/java/org/eclipse/che/multiuser/keycloak/server/KeycloakServiceClient.java
+++ b/multiuser/keycloak/che-multiuser-keycloak-server/src/main/java/org/eclipse/che/multiuser/keycloak/server/KeycloakServiceClient.java
@@ -139,2 +139,5 @@
           ServerException, UnauthorizedException {
+    if (!isValidOAuthProvider(oauthProvider)) {
+      throw new BadRequestException("Invalid OAuth provider: " + oauthProvider);
+    }
     String url =
@@ -158,2 +161,8 @@
   }
+
+  private boolean isValidOAuthProvider(String oauthProvider) {
+    // Define a list of allowed OAuth providers
+    List<String> allowedProviders = Arrays.asList("google", "github", "facebook");
+    return allowedProviders.contains(oauthProvider);
+  }
 
EOF
@@ -139,2 +139,5 @@
ServerException, UnauthorizedException {
if (!isValidOAuthProvider(oauthProvider)) {
throw new BadRequestException("Invalid OAuth provider: " + oauthProvider);
}
String url =
@@ -158,2 +161,8 @@
}

private boolean isValidOAuthProvider(String oauthProvider) {
// Define a list of allowed OAuth providers
List<String> allowedProviders = Arrays.asList("google", "github", "facebook");
return allowedProviders.contains(oauthProvider);
}

Copilot is powered by AI and may make mistakes. Always verify output.
// Unspecific errors always returned from Keycloak as 502 + HTML error page.
// So try to handle that case separately
if (responseCode == 502) {
Matcher matcher = errorPageMessagePattern.matcher(read);

Check failure

Code scanning / CodeQL

Polynomial regular expression used on uncontrolled data High

This
regular expression
that depends on a
user-provided value
may run slow on strings starting with '' and with many repetitions of 'a'.
}
String accountLinkUrl =
keycloakServiceClient.getAccountLinkingURL(jwtToken, oauthProvider, redirectAfterLogin);
return Response.temporaryRedirect(URI.create(accountLinkUrl)).build();

Check warning

Code scanning / CodeQL

URL redirection from remote source Medium

Untrusted URL redirection depends on a
user-provided value
.
Untrusted URL redirection depends on a
user-provided value
.

Copilot Autofix

AI 8 months ago

To fix the issue, we need to validate the accountLinkUrl before using it in the redirection. This can be achieved by ensuring that the URL is either relative or points to a trusted domain. Alternatively, we can maintain a whitelist of valid redirect URLs and check the constructed URL against this list.

The best approach here is to validate the accountLinkUrl to ensure it points to a trusted domain. If the URL is invalid or does not match the trusted domain, we should redirect the user to a safe fallback page (e.g., an error page).


Suggested changeset 1
multiuser/keycloak/che-multiuser-keycloak-server/src/main/java/org/eclipse/che/multiuser/keycloak/server/oauth2/DelegatedOAuthAPI.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/multiuser/keycloak/che-multiuser-keycloak-server/src/main/java/org/eclipse/che/multiuser/keycloak/server/oauth2/DelegatedOAuthAPI.java b/multiuser/keycloak/che-multiuser-keycloak-server/src/main/java/org/eclipse/che/multiuser/keycloak/server/oauth2/DelegatedOAuthAPI.java
--- a/multiuser/keycloak/che-multiuser-keycloak-server/src/main/java/org/eclipse/che/multiuser/keycloak/server/oauth2/DelegatedOAuthAPI.java
+++ b/multiuser/keycloak/che-multiuser-keycloak-server/src/main/java/org/eclipse/che/multiuser/keycloak/server/oauth2/DelegatedOAuthAPI.java
@@ -65,3 +65,16 @@
         keycloakServiceClient.getAccountLinkingURL(jwtToken, oauthProvider, redirectAfterLogin);
-    return Response.temporaryRedirect(URI.create(accountLinkUrl)).build();
+    
+    try {
+        URI accountLinkUri = URI.create(accountLinkUrl);
+        // Validate that the URL is either relative or points to a trusted domain
+        if (!accountLinkUri.isAbsolute() || "trusted-domain.com".equals(accountLinkUri.getHost())) {
+            return Response.temporaryRedirect(accountLinkUri).build();
+        } else {
+            // Redirect to a safe fallback page if validation fails
+            return Response.temporaryRedirect(URI.create("/error.html")).build();
+        }
+    } catch (IllegalArgumentException e) {
+        // Handle invalid URI syntax
+        return Response.temporaryRedirect(URI.create("/error.html")).build();
+    }
   }
EOF
@@ -65,3 +65,16 @@
keycloakServiceClient.getAccountLinkingURL(jwtToken, oauthProvider, redirectAfterLogin);
return Response.temporaryRedirect(URI.create(accountLinkUrl)).build();

try {
URI accountLinkUri = URI.create(accountLinkUrl);
// Validate that the URL is either relative or points to a trusted domain
if (!accountLinkUri.isAbsolute() || "trusted-domain.com".equals(accountLinkUri.getHost())) {
return Response.temporaryRedirect(accountLinkUri).build();
} else {
// Redirect to a safe fallback page if validation fails
return Response.temporaryRedirect(URI.create("/error.html")).build();
}
} catch (IllegalArgumentException e) {
// Handle invalid URI syntax
return Response.temporaryRedirect(URI.create("/error.html")).build();
}
}
Copilot is powered by AI and may make mistakes. Always verify output.
validator.validate(keycloakToken);
token = tokenProvider.obtainGitHubToken(keycloakToken);
} catch (KeycloakException e) {
return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();

Check warning

Code scanning / CodeQL

Information exposure through an error message Medium

Error information
can be exposed to an external user.

Copilot Autofix

AI 8 months ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

} catch (KeycloakException e) {
return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
}
return Response.ok(token).build();

Check warning

Code scanning / CodeQL

Cross-site scripting Medium

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

Copilot Autofix

AI 8 months ago

To fix the issue, the token value should be properly sanitized or encoded before being included in the HTTP response. Since the Response.ok() method is used to send the token back to the client, we should ensure that the token is safe for inclusion in the response. The best approach is to use contextual output encoding, such as JSON encoding, to ensure that the token is treated as a plain string and not executable code.

In this case, we will JSON-encode the token value before including it in the response. This ensures that any special characters in the token are escaped, preventing them from being interpreted as executable code.


Suggested changeset 1
multiuser/keycloak/che-multiuser-keycloak-token-provider/src/main/java/org/eclipse/che/multiuser/keycloak/token/provider/contoller/TokenController.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/multiuser/keycloak/che-multiuser-keycloak-token-provider/src/main/java/org/eclipse/che/multiuser/keycloak/token/provider/contoller/TokenController.java b/multiuser/keycloak/che-multiuser-keycloak-token-provider/src/main/java/org/eclipse/che/multiuser/keycloak/token/provider/contoller/TokenController.java
--- a/multiuser/keycloak/che-multiuser-keycloak-token-provider/src/main/java/org/eclipse/che/multiuser/keycloak/token/provider/contoller/TokenController.java
+++ b/multiuser/keycloak/che-multiuser-keycloak-token-provider/src/main/java/org/eclipse/che/multiuser/keycloak/token/provider/contoller/TokenController.java
@@ -89,3 +89,3 @@
     }
-    return Response.ok(token).build();
+    return Response.ok("{\"token\":\"" + token.replace("\"", "\\\"") + "\"}").build();
   }
EOF
@@ -89,3 +89,3 @@
}
return Response.ok(token).build();
return Response.ok("{\"token\":\"" + token.replace("\"", "\\\"") + "\"}").build();
}
Copilot is powered by AI and may make mistakes. Always verify output.
validator.validate(keycloakToken);
token = tokenProvider.obtainOsoToken(keycloakToken);
} catch (KeycloakException e) {
return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();

Check warning

Code scanning / CodeQL

Information exposure through an error message Medium

Error information
can be exposed to an external user.

Copilot Autofix

AI 8 months ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

@BeforeMethod
public void createEntities() throws Exception {
kpg = KeyPairGenerator.getInstance(ALGORITHM);
kpg.initialize(KEY_SIZE);

Check failure

Code scanning / CodeQL

Use of a cryptographic algorithm with insufficient key size High test

This
key size
is less than the recommended key size of 2048 bits.

Copilot Autofix

AI 8 months ago

To fix the issue, the KEY_SIZE constant should be updated to use a secure key size of at least 2048 bits for RSA encryption. This ensures compliance with modern cryptographic standards and mitigates the risk of brute force attacks. The change will involve updating the value of KEY_SIZE and ensuring that all references to it use the updated value.


Suggested changeset 1
multiuser/machine-auth/che-multiuser-machine-authentication/src/test/java/org/eclipse/che/multiuser/machine/authentication/server/signature/SignatureKeyManagerTest.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/multiuser/machine-auth/che-multiuser-machine-authentication/src/test/java/org/eclipse/che/multiuser/machine/authentication/server/signature/SignatureKeyManagerTest.java b/multiuser/machine-auth/che-multiuser-machine-authentication/src/test/java/org/eclipse/che/multiuser/machine/authentication/server/signature/SignatureKeyManagerTest.java
--- a/multiuser/machine-auth/che-multiuser-machine-authentication/src/test/java/org/eclipse/che/multiuser/machine/authentication/server/signature/SignatureKeyManagerTest.java
+++ b/multiuser/machine-auth/che-multiuser-machine-authentication/src/test/java/org/eclipse/che/multiuser/machine/authentication/server/signature/SignatureKeyManagerTest.java
@@ -49,3 +49,3 @@
 
-  private static final int KEY_SIZE = 512;
+  private static final int KEY_SIZE = 2048;
   private static final String ALGORITHM = "RSA";
EOF
@@ -49,3 +49,3 @@

private static final int KEY_SIZE = 512;
private static final int KEY_SIZE = 2048;
private static final String ALGORITHM = "RSA";
Copilot is powered by AI and may make mistakes. Always verify output.
.createQuery(findByWorkerQuery, WorkspaceImpl.class)
.setParameter("userId", userId)
.setMaxResults(maxItems)
.setFirstResult((int) skipCount)

Check failure

Code scanning / CodeQL

User-controlled data in numeric cast Critical

This cast to a narrower type depends on a
user-provided value
, potentially causing truncation.
@openshift-ci openshift-ci bot added the lgtm label May 9, 2025
@openshift-ci openshift-ci bot removed the lgtm label May 9, 2025
@openshift-ci
Copy link

openshift-ci bot commented May 9, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: svor, tolusha, vinokurig

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@vinokurig vinokurig merged commit 744041e into main May 9, 2025
27 of 28 checks passed
@vinokurig vinokurig deleted the revertCleanUp branch May 9, 2025 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants