Skip to content

Commit

Permalink
Check if maxage header value is valid before setting it
Browse files Browse the repository at this point in the history
  • Loading branch information
Bart Thierens committed Feb 1, 2024
1 parent 8447501 commit 9cb2de8
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ protected String getHeaderValue(HttpServletRequest request) {
Resource resource = getResource(slingRequest);
if (resource != null) {
String headerValue = resource.getValueMap().get(propertyName, String.class);
return HEADER_PREFIX + headerValue;
if (isValidMaxAgeValue(headerValue)) {
return HEADER_PREFIX + headerValue;
}
}
}
log.debug("An error occurred, falling back to the default max age value of this filter");
Expand All @@ -119,6 +121,15 @@ protected final void doActivate(ComponentContext context) throws Exception {
inheritPropertyValue = PropertiesUtil.toString(properties.get(PROP_INHERIT_PROPERTY_VALUE), "INHERIT");
}

private boolean isValidMaxAgeValue(String headerValue) {
try {
Integer.parseInt(headerValue);
return true;
} catch(NumberFormatException e) {
return false;
}
}

public String toString() {
return this.getClass().getName() + "[property-name:" + propertyName + ",fallback-max-age:" + super.getHeaderValue(null) + "]";
}
Expand Down

0 comments on commit 9cb2de8

Please sign in to comment.