Skip to content

Commit 17138d6

Browse files
committed
Fix incorrect weak ETag validation
1 parent 4f607b5 commit 17138d6

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

spring-web/src/main/java/org/springframework/http/HttpHeaders.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1073,8 +1073,8 @@ public long getDate() {
10731073
*/
10741074
public void setETag(@Nullable String etag) {
10751075
if (etag != null) {
1076-
Assert.isTrue(etag.startsWith("\"") || etag.startsWith("W/"),
1077-
"Invalid ETag: does not start with W/ or \"");
1076+
Assert.isTrue(etag.startsWith("\"") || etag.startsWith("W/\""),
1077+
"Invalid ETag: does not start with W/\" or \"");
10781078
Assert.isTrue(etag.endsWith("\""), "Invalid ETag: does not end with \"");
10791079
set(ETAG, etag);
10801080
}

spring-web/src/test/java/org/springframework/http/HttpHeadersTests.java

+6
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,12 @@ void illegalETag() {
219219
assertThatIllegalArgumentException().isThrownBy(() -> headers.setETag(eTag));
220220
}
221221

222+
@Test
223+
void illegalETagWithoutQuoteAfterWSlash() {
224+
String etag = "W/v2.6\"";
225+
assertThatIllegalArgumentException().as("Invalid Weak ETag").isThrownBy(() -> headers.setETag(etag));
226+
}
227+
222228
@Test
223229
void ifMatch() {
224230
String ifMatch = "\"v2.6\"";

0 commit comments

Comments
 (0)