Skip to content

security upgrade: the core project j2html had an insecure dependency … #229

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
fail-fast: false
matrix:
java_version: [1.8, 11, 17]
java_version: [11, 17, 21]
os: [windows-latest, macOS-latest, ubuntu-latest]

steps:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ buildNumber.properties
### IntelliJ ###
*.iml
.idea/

target
21 changes: 21 additions & 0 deletions GETTING_STARTED.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Getting started

### Build all projects:
- `mvn clean install`

### Core project
- The core project is situated in the `j2html` directory. When building, source code is generated using the maven plugin from project `j2html-codegen`

### Extra projects
- `j2html-website` - the project website (using j2html code) that runs via Javalin (https://javalin.io/)
- `j2html-codegen` - maven plugin for generating Java sources from a configured collection of tags (in a .model file).
- `j2html-mathml` - a mathml extension

### Hints when using Intellij:
- Mark directory `j2html/target/generated-sources/j2html-codegen` as Generated Sources Root
- Mark directory `j2html-ext-mathml/target/generated-sources/j2html-codegen` as Generated Sources Root

### Security check on dependencies
- Type `mvn org.owasp:dependency-check-maven:6.5.3:aggregate` and wait for the generated security report


4 changes: 2 additions & 2 deletions j2html-codegen/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.8.4</version>
<version>3.8.8</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.6.0</version>
<version>3.6.4</version>
<scope>provided</scope>
</dependency>

Expand Down
2 changes: 0 additions & 2 deletions j2html-website/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@
<dependency>
<groupId>io.javalin</groupId>
<artifactId>javalin</artifactId>
<version>4.0.0.ALPHA2</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.26</version>
</dependency>

<dependency>
Expand Down
21 changes: 18 additions & 3 deletions j2html-website/src/main/java/app/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,27 @@
import app.controllers.PageController;
import io.javalin.Javalin;
import io.javalin.http.staticfiles.Location;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;

public class Main {
private static final Logger LOG = LoggerFactory.getLogger(Main.class);

public static void main(String[] args) {
String path = "./src/main/resources/public";
File file = new File(path);

try {
LOG.info("static files served from location: {}, ready {} ", file.getCanonicalFile(), file.exists());
} catch (IOException ex) {
throw new IllegalStateException(ex);
}

public static void main(String[] args) {
Javalin app = Javalin.create(config ->
config.addStaticFiles("website/src/main/resources/public", Location.EXTERNAL)
Javalin app = Javalin.create(
config -> config.staticFiles.add(path, Location.EXTERNAL)
).start(8888);

app.get("/", PageController::serveIndex);
Expand Down
8 changes: 7 additions & 1 deletion j2html/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,15 @@

<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<artifactId>velocity-engine-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<packaging>jar</packaging>
Expand Down
4 changes: 2 additions & 2 deletions j2html/src/test/java/j2html/PerformanceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ public class PerformanceTest {
@Rule
public TestRule benchmarkRun = new BenchmarkRule();

private String shortTestString = "<body>\n"
private final String shortTestString = "<body>\n"
+ " <h1 class=\"example\">Heading!</h1>\n"
+ " <img src=\"img/hello.png\">\n"
+ "</body>";

// syntax-highlighted getting started example from j2html.com:
private String longTestString =
private final String longTestString =
"<pre class=\" language-java\"><code class=\" language-java\"><span class=\"token keyword\">import</span> <span class=\"token keyword\">static</span> j2html<span class=\"token punctuation\">.</span>TagCreator<span class=\"token punctuation\">.</span>*<span class=\"token punctuation\">;</span>\n"
+ "\n"
+ "<span class=\"token keyword\">public</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">Main</span> <span class=\"token punctuation\">{</span>\n"
Expand Down
2 changes: 1 addition & 1 deletion j2html/src/test/java/j2html/RenderPerformanceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class RenderPerformanceTest {
@Rule
public TestRule benchmarkRun = new BenchmarkRule();
String expected = "<html><head><title>Browsertitle</title></head><body><h1>Hello World!</h1><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><p>Hello World!</p></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div><h2 id=\"title\" class=\"visible-small\">Hello World!</h2><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><p>Hello World!</p></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div><h2>Hello World!</h2><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><p>Hello World!</p></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div><h2 id=\"title\" class=\"visible-small\">Hello World!</h2><div class=\"button\"><div class=\"button-text\">Action!</div></div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><p>Hello World!</p></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div><h2>Hello World!</h2><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><p>Hello World!</p></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div><h1>Hello World!</h1><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><p>Hello World!</p></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div><h2>Hello World!</h2><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><p>Hello World!</p></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div><h2>Hello World!</h2><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><p>Hello World!</p></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div><h2>Hello World!</h2><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><p>Hello World!</p></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div><h2>Hello World!</h2><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><p>Hello World!</p></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></body></html>";
private DomContent template;
private final DomContent template;

public RenderPerformanceTest() {
this.template =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ public class RenderPerformanceComparisonTest {

@Test
public void j2htmlPerformance() throws Exception {
TestJ2html.helloWorld();
TestJ2html.fiveHundredEmployees();
TestJ2html.macros();
TestJ2html.multiplicationTable();
TestOptionsForJ2html.helloWorld();
TestOptionsForJ2html.fiveHundredEmployees();
TestOptionsForJ2html.macros();
TestOptionsForJ2html.multiplicationTable();
}

@Test
public void velocityPerformance() throws Exception {
TestVelocity.helloWorld();
TestVelocity.fiveHundredEmployees();
TestVelocity.macros();
TestVelocity.multiplicationTable();
TestOptionsForVelocity.helloWorld();
TestOptionsForVelocity.fiveHundredEmployees();
TestOptionsForVelocity.macros();
TestOptionsForVelocity.multiplicationTable();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import j2html.comparison.j2html.Macros;
import j2html.comparison.j2html.MultiplicationTable;

public class TestJ2html {
/**
* Options are used in {@link RenderPerformanceComparisonTest}
*/
class TestOptionsForJ2html {

public static String helloWorld() {
return HelloWorld.tag.render();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;

public class TestVelocity {
/**
* Options are used in {@link RenderPerformanceComparisonTest}
*/
class TestOptionsForVelocity {

private static VelocityEngine velocityEngine;
private static final VelocityEngine velocityEngine;

static {
velocityEngine = new VelocityEngine();
Expand Down Expand Up @@ -45,6 +48,8 @@ public static String multiplicationTable() {
return render("/comparison/velocity/multiplicationTable.vm", model);
}



public static void main(String[] args) {
System.out.println(multiplicationTable());
}
Expand Down
20 changes: 14 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,17 @@
<maven.compiler.source>${jdk.version}</maven.compiler.source>
<maven.compiler.target>${jdk.version}</maven.compiler.target>

<junit.version>4.13.1</junit.version>
<junit.version>4.13.2</junit.version>
<mockito.version>4.8.1</mockito.version>
<hamcrest-library.version>1.3</hamcrest-library.version>
<commons-lang3.version>3.0</commons-lang3.version>
<junit-benchmarks.version>0.7.2</junit-benchmarks.version>
<apache-velocity.version>1.7</apache-velocity.version>
<jsoup.version>1.14.3</jsoup.version>
<apache-velocity.version>2.3</apache-velocity.version>
<hsqldb.version>2.7.2</hsqldb.version>
<jsoup.version>1.17.2</jsoup.version>
<javapoet.version>1.9.0</javapoet.version>
<javalin.version>4.0.0.ALPHA2</javalin.version>
<slf4j-simple.version>1.7.26</slf4j-simple.version>
<javalin.version>6.1.3</javalin.version>
<slf4j-simple.version>2.0.13</slf4j-simple.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -109,12 +110,19 @@
</dependency>

<!-- performance test dependencies -->

<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<artifactId>velocity-engine-core</artifactId>
<version>${apache-velocity.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>${hsqldb.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
Expand Down
Loading