Skip to content
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

[backend] Fix Regular expression injection #2137

Merged
merged 2 commits into from
Dec 31, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.openbas.rest.challenge.response.ChallengeResult;
import io.openbas.rest.challenge.response.ChallengesReader;
import io.openbas.rest.exception.ElementNotFoundException;
import io.openbas.rest.exception.InputValidationException;
import io.openbas.rest.helper.RestBehavior;
import io.openbas.service.ChallengeService;
import jakarta.transaction.Transactional;
Expand Down Expand Up @@ -133,7 +134,9 @@

@PostMapping("/api/challenges/{challengeId}/try")
public ChallengeResult tryChallenge(
@PathVariable String challengeId, @Valid @RequestBody ChallengeTryInput input) {
@PathVariable String challengeId, @Valid @RequestBody ChallengeTryInput input)
throws InputValidationException {
validateUUID(challengeId);

Check warning on line 139 in openbas-api/src/main/java/io/openbas/rest/challenge/ChallengeApi.java

View check run for this annotation

Codecov / codecov/patch

openbas-api/src/main/java/io/openbas/rest/challenge/ChallengeApi.java#L139

Added line #L139 was not covered by tests
return challengeService.tryChallenge(challengeId, input);
}

Expand All @@ -143,7 +146,11 @@
@PathVariable String exerciseId,
@PathVariable String challengeId,
@Valid @RequestBody ChallengeTryInput input,
@RequestParam Optional<String> userId) {
@RequestParam Optional<String> userId)
throws InputValidationException {
validateUUID(exerciseId);
validateUUID(challengeId);

Check warning on line 152 in openbas-api/src/main/java/io/openbas/rest/challenge/ChallengeApi.java

View check run for this annotation

Codecov / codecov/patch

openbas-api/src/main/java/io/openbas/rest/challenge/ChallengeApi.java#L151-L152

Added lines #L151 - L152 were not covered by tests

final User user = impersonateUser(userRepository, userId);
if (user.getId().equals(ANONYMOUS)) {
throw new UnsupportedOperationException("User must be logged or dynamic player is required");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,12 @@
}
}
}

protected void validateUUID(final String id) throws InputValidationException {
try {
UUID.fromString(id);
} catch (IllegalArgumentException e) {
throw new InputValidationException("id", "The ID is not a valid UUID: " + id);
}
}

Check warning on line 216 in openbas-api/src/main/java/io/openbas/rest/helper/RestBehavior.java

View check run for this annotation

Codecov / codecov/patch

openbas-api/src/main/java/io/openbas/rest/helper/RestBehavior.java#L212-L216

Added lines #L212 - L216 were not covered by tests
}
Loading