Skip to content

Commit 64572b2

Browse files
committed
added new vuln code
1 parent eac265a commit 64572b2

File tree

5 files changed

+90
-1
lines changed

5 files changed

+90
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<dependency>
3232
<groupId>io.github.pixee</groupId>
3333
<artifactId>java-security-toolkit</artifactId>
34-
<version>1.1.2</version>
34+
<version>1.2.0</version>
3535
</dependency>
3636
</dependencies>
3737
</dependencyManagement>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.acme.jndi;
2+
3+
import io.github.pixee.security.JNDI;
4+
import jakarta.ws.rs.GET;
5+
import jakarta.ws.rs.Path;
6+
import jakarta.ws.rs.QueryParam;
7+
8+
import javax.naming.Context;
9+
import javax.naming.InitialContext;
10+
import javax.naming.NamingException;
11+
12+
@Path("/unsafe-jndi-lookup")
13+
public class JNDIVulnFixed2 {
14+
15+
@GET
16+
public String lookupResource(@QueryParam("resource") final String resource) throws NamingException {
17+
Context ctx = new InitialContext();
18+
Object obj = JNDI.limitedContext(ctx).lookup(resource);
19+
return String.valueOf(obj);
20+
}
21+
22+
23+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.acme.jndi;
2+
3+
import jakarta.ws.rs.GET;
4+
import jakarta.ws.rs.Path;
5+
import jakarta.ws.rs.QueryParam;
6+
7+
import javax.naming.Context;
8+
import javax.naming.InitialContext;
9+
import javax.naming.NamingException;
10+
import java.util.Set;
11+
import java.util.regex.Pattern;
12+
13+
@Path("/unsafe-jndi-lookup")
14+
public class JNDIVulnFixed3 {
15+
16+
@GET
17+
public String lookupResource(@QueryParam("resource") final String resource) throws NamingException {
18+
Context ctx = new InitialContext();
19+
20+
if(Pattern.compile("^ldap://$").matcher(resource).matches()) {
21+
throw new SecurityException("Illegal JNDI resource name: " + resource);
22+
}
23+
Object obj = ctx.lookup(resource);
24+
return String.valueOf(obj);
25+
}
26+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.acme.sql;
2+
3+
import jakarta.ws.rs.GET;
4+
import jakarta.ws.rs.Path;
5+
import jakarta.ws.rs.QueryParam;
6+
7+
import java.sql.Connection;
8+
import java.sql.SQLException;
9+
import java.sql.Statement;
10+
11+
@Path("/unsafe-sql-injection")
12+
public class SQLInjectionVuln {
13+
@GET
14+
public String lookupResource(Connection connection, @QueryParam("resource") final String resource) throws SQLException {
15+
Statement statement = connection.createStatement();
16+
statement.executeQuery("select * from users where name = '" + resource + "'");
17+
return "ok";
18+
}
19+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.acme.sql;
2+
3+
import jakarta.ws.rs.GET;
4+
import jakarta.ws.rs.Path;
5+
import jakarta.ws.rs.QueryParam;
6+
7+
import java.sql.Connection;
8+
import java.sql.PreparedStatement;
9+
import java.sql.SQLException;
10+
import java.sql.Statement;
11+
12+
@Path("/unsafe-sql-injection")
13+
public class SQLInjectionVulnFixed {
14+
@GET
15+
public String lookupResource(Connection connection, @QueryParam("resource") final String resource) throws SQLException {
16+
PreparedStatement statement = connection.prepareStatement("select * from users where name = ?");
17+
statement.setString(1, resource);
18+
statement.executeQuery();
19+
return "ok";
20+
}
21+
}

0 commit comments

Comments
 (0)