Skip to content

Commit b7f97c7

Browse files
authored
Merge pull request #64 from contentstack/fix/DX-2530-snyk-issues
Snyk fixes and code quality fixes
2 parents fe01004 + 2de2ec8 commit b7f97c7

File tree

7 files changed

+89
-52
lines changed

7 files changed

+89
-52
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838

3939
# Initializes the CodeQL tools for scanning.
4040
- name: Initialize CodeQL
41-
uses: github/codeql-action/init@v2
41+
uses: github/codeql-action/init@v3
4242
with:
4343
languages: ${{ matrix.language }}
4444
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -52,7 +52,7 @@ jobs:
5252
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
5353
# If this step fails, then you should remove it and run the build manually (see below)
5454
- name: Autobuild
55-
uses: github/codeql-action/autobuild@v2
55+
uses: github/codeql-action/autobuild@v3
5656

5757
# ℹ️ Command-line programs to run using the OS shell.
5858
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
@@ -65,4 +65,4 @@ jobs:
6565
# ./location_of_script_within_repo/buildscript.sh
6666

6767
- name: Perform CodeQL Analysis
68-
uses: github/codeql-action/analyze@v2
68+
uses: github/codeql-action/analyze@v3

.mvn/wrapper/MavenWrapperDownloader.java

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,32 @@ public class MavenWrapperDownloader {
2222

2323
private static final String WRAPPER_VERSION = "0.5.6";
2424
/**
25-
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
25+
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl'
26+
* is provided.
2627
*/
2728
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
28-
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
29+
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
2930

3031
/**
31-
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
32-
* use instead of the default one.
32+
* Path to the maven-wrapper.properties file, which might contain a
33+
* downloadUrl property to use instead of the default one.
3334
*/
34-
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
35-
".mvn/wrapper/maven-wrapper.properties";
35+
private static final String MAVEN_WRAPPER_PROPERTIES_PATH
36+
= ".mvn/wrapper/maven-wrapper.properties";
3637

3738
/**
3839
* Path where the maven-wrapper.jar will be saved to.
3940
*/
40-
private static final String MAVEN_WRAPPER_JAR_PATH =
41-
".mvn/wrapper/maven-wrapper.jar";
41+
private static final String MAVEN_WRAPPER_JAR_PATH
42+
= ".mvn/wrapper/maven-wrapper.jar";
4243

4344
/**
44-
* Name of the property which should be used to override the default download url for the wrapper.
45+
* Name of the property which should be used to override the default
46+
* download url for the wrapper.
4547
*/
4648
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
4749

48-
public static void main(String args[]) {
50+
public static void main(String args[]) throws Exception {
4951
System.out.println("- Downloader started");
5052
File baseDirectory = new File(args[0]);
5153
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
@@ -54,30 +56,34 @@ public static void main(String args[]) {
5456
// wrapperUrl parameter.
5557
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
5658
String url = DEFAULT_DOWNLOAD_URL;
57-
if(mavenWrapperPropertyFile.exists()) {
58-
FileInputStream mavenWrapperPropertyFileInputStream = null;
59-
try {
60-
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
61-
Properties mavenWrapperProperties = new Properties();
62-
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
63-
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
64-
} catch (IOException e) {
65-
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
66-
} finally {
59+
try {
60+
if (mavenWrapperPropertyFile.exists() && mavenWrapperPropertyFile.getCanonicalPath().startsWith(baseDirectory.getCanonicalPath())) {
61+
FileInputStream mavenWrapperPropertyFileInputStream = null;
6762
try {
68-
if(mavenWrapperPropertyFileInputStream != null) {
69-
mavenWrapperPropertyFileInputStream.close();
70-
}
63+
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
64+
Properties mavenWrapperProperties = new Properties();
65+
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
66+
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
7167
} catch (IOException e) {
72-
// Ignore ...
68+
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
69+
} finally {
70+
try {
71+
if (mavenWrapperPropertyFileInputStream != null) {
72+
mavenWrapperPropertyFileInputStream.close();
73+
}
74+
} catch (IOException e) {
75+
// Ignore ...
76+
}
7377
}
7478
}
79+
} catch (IOException e) {
80+
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
7581
}
7682
System.out.println("- Downloading from: " + url);
7783

7884
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
79-
if(!outputFile.getParentFile().exists()) {
80-
if(!outputFile.getParentFile().mkdirs()) {
85+
if (!outputFile.getParentFile().exists()) {
86+
if (!outputFile.getParentFile().mkdirs()) {
8187
System.out.println(
8288
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
8389
}
@@ -87,7 +93,7 @@ public static void main(String args[]) {
8793
downloadFileFromURL(url, outputFile);
8894
System.out.println("Done");
8995
System.exit(0);
90-
} catch (Throwable e) {
96+
} catch (IOException e) {
9197
System.out.println("- Error downloading");
9298
e.printStackTrace();
9399
System.exit(1);
@@ -108,9 +114,9 @@ protected PasswordAuthentication getPasswordAuthentication() {
108114
URL website = new URL(urlString);
109115
ReadableByteChannel rbc;
110116
rbc = Channels.newChannel(website.openStream());
111-
FileOutputStream fos = new FileOutputStream(destination);
112-
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
113-
fos.close();
117+
try (FileOutputStream fos = new FileOutputStream(destination.getCanonicalPath().replaceAll("^/+", "").split("\\?")[0])) {
118+
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
119+
}
114120
rbc.close();
115121
}
116122

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2012 - 2021 Contentstack
3+
Copyright (c) 2012 - 2025 Contentstack
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This step-by-step guide details how to create a Java sample webapp via spring-bo
1111

1212
- An IDE, for example, [IntelliJ IDEA](https://www.jetbrains.com/idea/download/) / [STS](https://spring.io/tools) / [VSCode](https://code.visualstudio.com/download) / [Ecllipse](https://www.eclipse.org/downloads/)
1313

14-
- [JDK 1.8 or later](https://www.oracle.com/in/java/technologies/javase/javase-jdk8-downloads.html)
14+
- [JDK 17 or later](https://www.oracle.com/in/java/technologies/downloads/#java17)
1515

1616
- Gradle 4+ or Maven 3.2+
1717

SECURITY.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Security
2+
3+
Contentstack takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations.
4+
5+
If you believe you have found a security vulnerability in any Contentstack-owned repository, please report it to us as described below.
6+
7+
## Reporting Security Issues
8+
9+
**Please do not report security vulnerabilities through public GitHub issues.**
10+
11+
Send email to [security@contentstack.com](mailto:security@contentstack.com).
12+
13+
You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message.
14+
15+
Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
16+
17+
- Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
18+
- Full paths of source file(s) related to the manifestation of the issue
19+
- The location of the affected source code (tag/branch/commit or direct URL)
20+
- Any special configuration required to reproduce the issue
21+
- Step-by-step instructions to reproduce the issue
22+
- Proof-of-concept or exploit code (if possible)
23+
- Impact of the issue, including how an attacker might exploit the issue
24+
25+
This information will help us triage your report more quickly.
26+
27+
[https://www.contentstack.com/trust/](https://www.contentstack.com/trust/)

pom.xml

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>org.springframework.boot</groupId>
88
<artifactId>spring-boot-starter-parent</artifactId>
9-
<version>3.1.4</version>
9+
<version>3.4.1</version>
1010
<relativePath/> <!-- lookup parent from repository -->
1111
</parent>
1212
<groupId>com.contentstack</groupId>
@@ -15,70 +15,71 @@
1515
<name>graphql-springboot-api-integration</name>
1616
<description>Demo project for graphql-springboot-api-integration</description>
1717
<properties>
18-
<java.version>1.8</java.version>
19-
<spring-boot.version>3.1.4</spring-boot.version>
20-
<json-smart.version>5.2.2</json-smart.version>
18+
<java.version>17</java.version>
19+
<spring-boot.version>3.4.1</spring-boot.version>
20+
<json-smart.version>2.5.2</json-smart.version>
2121
</properties>
2222

2323
<dependencies>
2424
<dependency>
2525
<groupId>org.springframework.boot</groupId>
2626
<artifactId>spring-boot-starter-web</artifactId>
27-
<version>${spring-boot.version}</version>
2827
</dependency>
2928
<dependency>
3029
<groupId>org.springframework.boot</groupId>
3130
<artifactId>spring-boot-starter-freemarker</artifactId>
32-
<version>${spring-boot.version}</version>
3331
</dependency>
3432
<dependency>
3533
<groupId>org.springframework.boot</groupId>
3634
<artifactId>spring-boot-starter-thymeleaf</artifactId>
37-
<version>${spring-boot.version}</version>
3835
</dependency>
3936
<dependency>
4037
<groupId>org.springframework.boot</groupId>
4138
<artifactId>spring-boot-starter</artifactId>
42-
<version>${spring-boot.version}</version>
4339
</dependency>
4440
<dependency>
4541
<groupId>io.github.cdimascio</groupId>
4642
<artifactId>java-dotenv</artifactId>
47-
<version>${json-smart.version}</version>
43+
<version>5.2.2</version>
4844
</dependency>
4945

5046
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
5147
<dependency>
5248
<groupId>org.projectlombok</groupId>
5349
<artifactId>lombok</artifactId>
54-
<version>1.18.30</version>
5550
<scope>provided</scope>
5651
</dependency>
5752

5853
<!-- https://mvnrepository.com/artifact/net.minidev/json-smart -->
5954
<dependency>
6055
<groupId>net.minidev</groupId>
6156
<artifactId>json-smart</artifactId>
62-
<version>2.5.0</version>
6357
</dependency>
6458

6559
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-test -->
6660
<dependency>
6761
<groupId>org.springframework.boot</groupId>
6862
<artifactId>spring-boot-test</artifactId>
69-
<version>${spring-boot.version}</version>
7063
<scope>test</scope>
7164
</dependency>
7265

7366

7467
</dependencies>
68+
<dependencyManagement>
69+
<dependencies>
70+
<dependency>
71+
<groupId>org.jetbrains.kotlin</groupId>
72+
<artifactId>kotlin-stdlib</artifactId>
73+
<version>1.6.0</version>
74+
</dependency>
75+
</dependencies>
76+
</dependencyManagement>
7577

7678
<build>
7779
<plugins>
7880
<plugin>
7981
<groupId>org.springframework.boot</groupId>
8082
<artifactId>spring-boot-maven-plugin</artifactId>
81-
<version>3.1.4</version>
8283
</plugin>
8384
</plugins>
8485
</build>

src/main/java/com/contentstack/gqlspring/Contentstack.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
import com.fasterxml.jackson.core.JsonProcessingException;
66
import com.fasterxml.jackson.databind.JsonNode;
77
import com.fasterxml.jackson.databind.ObjectMapper;
8+
89
import io.github.cdimascio.dotenv.Dotenv;
10+
911
import org.jetbrains.annotations.NotNull;
1012

1113
import java.util.Collections;
14+
import java.util.logging.Logger;
1215

1316
public class Contentstack {
1417

@@ -26,7 +29,7 @@ public static <T> T convertToObject(Class<T> clazz, String jsonString) {
2629
ObjectMapper mapper = new ObjectMapper();
2730
return mapper.readValue(jsonString, clazz);
2831
} catch (Exception e) {
29-
e.printStackTrace();
32+
Logger.getLogger(Contentstack.class.getName()).severe(e.getMessage());
3033
return null;
3134
}
3235
}
@@ -63,7 +66,7 @@ public Object getQuery(@NotNull String query, @NotNull String nodeBy, Class<?> c
6366
return convertToObject(cls, jsonNode.toString());
6467

6568
} catch (Exception e) {
66-
e.printStackTrace();
69+
Logger.getLogger(Contentstack.class.getName()).severe(e.getMessage());
6770
}
6871
return null;
6972
}
@@ -73,7 +76,7 @@ private Object toListObject(Class<?> cls, String string) {
7376
try {
7477
return Collections.singletonList(new ObjectMapper().readValue(string, cls)).get(0);
7578
} catch (JsonProcessingException e) {
76-
e.printStackTrace();
79+
Logger.getLogger(Contentstack.class.getName()).severe(e.getMessage());
7780
}
7881
return null;
7982
}
@@ -132,7 +135,7 @@ public Object blogPostById(String id, Class<?> cls) {
132135
JsonNode strResponse = graphqlBuilderInstance.fetch().get("data").get("all_blog_post").get(ITEMS).get(0);
133136
return convertToObject(cls, strResponse.toString());
134137
} catch (Exception e) {
135-
e.printStackTrace();
138+
Logger.getLogger(Contentstack.class.getName()).severe(e.getMessage());
136139
throw new IllegalArgumentException("Invalid = graphql query");
137140
}
138141
}

0 commit comments

Comments
 (0)