Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/*
* SPDX-FileCopyrightText: Copyright © 2017 WebGoat authors
* SPDX-License-Identifier: GPL-2.0-or-later
Expand Down Expand Up @@ -45,12 +46,17 @@ public Servers(LessonDataSource dataSource) {
public List<Server> sort(@RequestParam String column) throws Exception {
List<Server> servers = new ArrayList<>();

// Validate column parameter against whitelist
List<String> allowedColumns = List.of("id", "hostname", "ip", "mac", "status", "description");
if (!allowedColumns.contains(column)) {
throw new IllegalArgumentException("Invalid column name");
}

try (var connection = dataSource.getConnection()) {
try (var statement =
connection.prepareStatement(
"select id, hostname, ip, mac, status, description from SERVERS where status <> 'out"
+ " of order' order by "
+ column)) {
"select id, hostname, ip, mac, status, description from SERVERS where status <> 'out of order' order by ?")) {
statement.setString(1, column);
try (var rs = statement.executeQuery()) {
while (rs.next()) {
Server server =
Expand Down