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

fix/80 regex large inputs vuln #118

Merged
merged 2 commits into from
Mar 25, 2024
Merged
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
16 changes: 10 additions & 6 deletions src/main/java/com/graqr/threshr/model/queryparam/Place.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import io.micronaut.serde.annotation.Serdeable;
import lombok.Data;

/**
* Place is a query parameter used when querying nearby target store locations. The query accepts either a zipcode
* or a city-state combo. See {@link com.graqr.threshr.Threshr#queryStoreLocations(Place)}.
*/
@Serdeable
@Data
public class Place {
Expand All @@ -17,15 +21,15 @@ public Place(String zipcode) {

public Place(String city, String state) {
String errorMessage = "";
if (!String.valueOf(city).matches("^([a-zA-Z\\u0080-\\u024F]+(?:. |-| |'))*[a-zA-Z\\u0080-\\u024F]*$")) {
errorMessage = "Invalid city string provided, \"" + city + "\". String provided " +
"must match this regex: \"^([a-zA-Z\\u0080-\\u024F]+(?:. |-| |'))*[a-zA-Z\\u0080-\\u024F]*$\".";
//match weird strings like D'Amoreport (texas) and Coeur D'Alene (idaho)
String pattern = "^([a-zA-Z|\\u0080-\\u024F]\\W?)*+$"; // *+ quantifier prevents backtracking
if (!String.valueOf(city).matches(pattern)) {
errorMessage = "Invalid city string provided, \"" + city + "\".";
} else if (city.isEmpty()) {
errorMessage = "String value for city cannot be empty.";
}
if (!String.valueOf(state).matches("^[A-Z][a-z]+(?: +[A-Z][a-z]+)*$")) {
errorMessage = "Invalid state string provided, \"" + state + "\". String provided " +
"must match this regex: \"^[A-Z][a-z]+(?: +[A-Z][a-z]+)*$\".";
if (!String.valueOf(state).matches(pattern)) {
errorMessage = "Invalid state string provided, \"" + state + "\".";
} else if (state.isEmpty()) {
errorMessage += "String value for state cannot be empty.";
}
Expand Down
Loading