Skip to content

Commit 9371948

Browse files
committed
Issue #12806 - UriCompliance listener reporting updates
1 parent 61f7736 commit 9371948

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/UriCompliance.java

+19-4
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ public enum Violation implements ComplianceViolation
102102

103103
/**
104104
* Allow truncated UTF-8 encodings to be substituted by the replacement character.
105+
* <p>
106+
* Note: This violation allows a subset of {@link #BAD_UTF8_ENCODING} behaviors meant to replicate LEGACY behaviors, and will be reported as {@link #BAD_UTF8_ENCODING}.
107+
* </p>
105108
*/
106109
TRUNCATED_UTF8_ENCODING("https://datatracker.ietf.org/doc/html/rfc5987#section-3.2.1", "Truncated UTF-8 encoding"),
107110

@@ -112,7 +115,7 @@ public enum Violation implements ComplianceViolation
112115

113116
/**
114117
* Allow path characters not allowed in the path portion of the URI and HTTP specs.
115-
* <p>This would allow characters that fall outside of the {@code unreserved / pct-encoded / sub-delims / ":" / "@"} ABNF</p>
118+
* <p>This would allow characters that fall outside the {@code unreserved / pct-encoded / sub-delims / ":" / "@"} ABNF</p>
116119
*/
117120
ILLEGAL_PATH_CHARACTERS("https://datatracker.ietf.org/doc/html/rfc3986#section-3.3", "Illegal Path Character"),
118121

@@ -426,18 +429,30 @@ private static Set<Violation> copyOf(Set<Violation> violations)
426429
return EnumSet.copyOf(violations);
427430
}
428431

432+
/**
433+
* Check the {@link HttpURI} against a configured {@link UriCompliance} to see if any detected violations
434+
* are allowed by the configured {@link UriCompliance}.
435+
*
436+
* @param compliance the configured {@link UriCompliance}.
437+
* @param uri the HttpURI.
438+
* @param listener listener to report violations to.
439+
* @return A string representing the violations that were not allowed by the configured {@link UriCompliance}, null if
440+
* the provided HttpURI either has no violations, or only had violations that are allowed by the {@link UriCompliance}
441+
*/
429442
public static String checkUriCompliance(UriCompliance compliance, HttpURI uri, ComplianceViolation.Listener listener)
430443
{
431444
if (uri.hasViolations())
432445
{
433446
StringBuilder violations = null;
434447
for (UriCompliance.Violation violation : uri.getViolations())
435448
{
449+
// Always report violation to listeners
450+
if (listener != null)
451+
listener.onComplianceViolation(new ComplianceViolation.Event(compliance, violation, uri.toString()));
452+
453+
// Only trigger a failure of the HttpURI for compliance reasons if the compliance doesn't allow for violation detected
436454
if (compliance == null || !compliance.allows(violation))
437455
{
438-
if (listener != null)
439-
listener.onComplianceViolation(new ComplianceViolation.Event(compliance, violation, uri.toString()));
440-
441456
if (violations == null)
442457
violations = new StringBuilder();
443458
else

0 commit comments

Comments
 (0)