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 8a056c0
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ 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;

Check warning on line 104 in bundle/src/main/java/com/adobe/acs/commons/http/headers/impl/PropertyBasedDispatcherMaxAgeHeaderFilter.java

View check run for this annotation

Codecov / codecov/patch

bundle/src/main/java/com/adobe/acs/commons/http/headers/impl/PropertyBasedDispatcherMaxAgeHeaderFilter.java#L104

Added line #L104 was not covered by tests
} else {
log.debug("Invalid value found in property for max-age header");

Check warning on line 106 in bundle/src/main/java/com/adobe/acs/commons/http/headers/impl/PropertyBasedDispatcherMaxAgeHeaderFilter.java

View check run for this annotation

Codecov / codecov/patch

bundle/src/main/java/com/adobe/acs/commons/http/headers/impl/PropertyBasedDispatcherMaxAgeHeaderFilter.java#L106

Added line #L106 was not covered by tests
}
}
}
log.debug("An error occurred, falling back to the default max age value of this filter");
Expand All @@ -119,6 +123,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;

Check warning on line 131 in bundle/src/main/java/com/adobe/acs/commons/http/headers/impl/PropertyBasedDispatcherMaxAgeHeaderFilter.java

View check run for this annotation

Codecov / codecov/patch

bundle/src/main/java/com/adobe/acs/commons/http/headers/impl/PropertyBasedDispatcherMaxAgeHeaderFilter.java#L128-L131

Added lines #L128 - L131 were not covered by tests
}
}

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

0 comments on commit 8a056c0

Please sign in to comment.