sonatype-lift[bot] commented on code in PR #1284:
URL: https://github.com/apache/solr/pull/1284#discussion_r1066264046


##########
solr/modules/jwt-auth/src/java/org/apache/solr/security/jwt/JWTAuthPlugin.java:
##########
@@ -297,6 +283,54 @@ public void init(Map<String, Object> pluginConfig) {
     lastInitTime = Instant.now();
   }
 
+  /**
+   * Given a configuration object of a file name or list of file names, read 
X509 certificates from
+   * each file
+   */
+  @SuppressWarnings("unchecked")
+  Collection<X509Certificate> readSslCertsFromFileOrList(Object 
trustedCertsFileObj) {
+    Collection<X509Certificate> certs = new HashSet<>();
+    if (trustedCertsFileObj instanceof String) {
+      String trustedCertsFile = (String) trustedCertsFileObj;
+      log.info("Reading trustedCerts from file {}", trustedCertsFile);
+      try {
+        certs.addAll(parseCertsFromFile(trustedCertsFile));
+      } catch (IOException e) {
+        throw new SolrException(
+            SolrException.ErrorCode.SERVER_ERROR, "Failed to read file " + 
trustedCertsFile, e);
+      }
+    } else if (trustedCertsFileObj instanceof List) {
+      List<String> trustedCertsFileList = (List<String>) trustedCertsFileObj;
+      log.info("Reading trustedCerts from list of files {}", 
trustedCertsFileList);
+      trustedCertsFileList.forEach(
+          f -> {
+            try {
+              certs.addAll(parseCertsFromFile(f));
+            } catch (IOException e) {
+              throw new SolrException(
+                  SolrException.ErrorCode.SERVER_ERROR, "Failed to read file " 
+ f, e);
+            }
+          });
+    } else {
+      throw new SolrException(
+          SolrException.ErrorCode.SERVER_ERROR, "trustedCertsFile is neither a 
String or List");
+    }
+    return certs;
+  }
+
+  /**
+   * Given a filename string, validate the file and then read any X509 
certificates from it
+   *
+   * @return list of certificates found in file
+   */
+  Collection<? extends X509Certificate> parseCertsFromFile(String 
certFileName) throws IOException {
+    Path certFilePath = Paths.get(certFileName);

Review Comment:
   <picture><img alt="7% of developers fix this issue" 
src="https://lift.sonatype.com/api/commentimage/fixrate/7/display.svg";></picture>
   
   
*[PATH_TRAVERSAL_IN](https://find-sec-bugs.github.io/bugs.htm#PATH_TRAVERSAL_IN):*
  This API 
(java/nio/file/Paths.get(Ljava/lang/String;[Ljava/lang/String;)Ljava/nio/file/Path;)
 reads a file whose location might be specified by user input
   
   ---
   
   <details><summary><b>â„šī¸ Learn about @sonatype-lift commands</b></summary>
   
   You can reply with the following commands. For example, reply with 
***@sonatype-lift ignoreall*** to leave out all findings.
   | **Command** | **Usage** |
   | ------------- | ------------- |
   | `@sonatype-lift ignore` | Leave out the above finding from this PR |
   | `@sonatype-lift ignoreall` | Leave out all the existing findings from this 
PR |
   | `@sonatype-lift exclude <file\|issue\|path\|tool>` | Exclude specified 
`file\|issue\|path\|tool` from Lift findings by updating your config.toml file |
   
   **Note:** When talking to LiftBot, you need to **refresh** the page to see 
its response.
   <sub>[Click here](https://github.com/apps/sonatype-lift/installations/new) 
to add LiftBot to another repo.</sub></details>
   
   
   
   ---
   
   Was this a good recommendation?
   [ [🙁 Not 
relevant](https://www.sonatype.com/lift-comment-rating?comment=367180506&lift_comment_rating=1)
 ] - [ [😕 Won't 
fix](https://www.sonatype.com/lift-comment-rating?comment=367180506&lift_comment_rating=2)
 ] - [ [😑 Not critical, will 
fix](https://www.sonatype.com/lift-comment-rating?comment=367180506&lift_comment_rating=3)
 ] - [ [🙂 Critical, will 
fix](https://www.sonatype.com/lift-comment-rating?comment=367180506&lift_comment_rating=4)
 ] - [ [😊 Critical, fixing 
now](https://www.sonatype.com/lift-comment-rating?comment=367180506&lift_comment_rating=5)
 ]



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to