Skip to content

Commit 939ae10

Browse files
committed
Remove isNonceBased() from header writers
Signed-off-by: Ziqin Wang <ziqin@wangziqin.net>
1 parent acf956a commit 939ae10

4 files changed

Lines changed: 0 additions & 46 deletions

File tree

web/src/main/java/org/springframework/security/web/header/writers/ContentSecurityPolicyHeaderWriter.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -194,17 +194,6 @@ public void setReportOnly(boolean reportOnly) {
194194
this.reportOnly = reportOnly;
195195
}
196196

197-
/**
198-
* Returns whether the content security policy is nonce-based. The CSP is considered
199-
* nonce-based if the configured {@code policyDirectives} string contains a
200-
* {@code {nonce}} placeholder.
201-
* @return whether the content security policy is nonce-based
202-
* @since 7.1
203-
*/
204-
public boolean isNonceBased() {
205-
return this.isNonceBased;
206-
}
207-
208197
@Override
209198
public String toString() {
210199
return getClass().getName() + " [policyDirectives=" + this.policyDirectives + "; reportOnly=" + this.reportOnly

web/src/main/java/org/springframework/security/web/server/header/ContentSecurityPolicyServerHttpHeadersWriter.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,6 @@ public void setReportOnly(boolean reportOnly) {
120120
this.reportOnly = reportOnly;
121121
}
122122

123-
/**
124-
* Returns whether the content security policy is nonce-based. The CSP is considered
125-
* nonce-based if the configured {@code policyDirectives} string contains a
126-
* {@code {nonce}} placeholder.
127-
* @return whether the content security policy is nonce-based
128-
* @since 7.1
129-
*/
130-
public boolean isNonceBased() {
131-
return this.isNonceBased;
132-
}
133-
134123
private static String resolveHeader(boolean reportOnly) {
135124
return reportOnly ? CONTENT_SECURITY_POLICY_REPORT_ONLY : CONTENT_SECURITY_POLICY;
136125
}

web/src/test/java/org/springframework/security/web/header/writers/ContentSecurityPolicyHeaderWriterTests.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -131,18 +131,6 @@ public void writeContentSecurityPolicyReportOnlyHeaderWhenNotPresent() {
131131
assertThat(this.response.getHeader(CONTENT_SECURITY_POLICY_REPORT_ONLY_HEADER)).isSameAs(value);
132132
}
133133

134-
@Test
135-
public void whenPolicyDirectivesContainNoncePlaceholderThenWriterIsNonceBased() {
136-
this.writer.setPolicyDirectives("script-src 'self' 'nonce-{nonce}'");
137-
assertThat(this.writer.isNonceBased()).isTrue();
138-
this.writer.setPolicyDirectives("script-src 'nonce-{nonce}'; style-src 'nonce-{nonce}'");
139-
assertThat(this.writer.isNonceBased()).isTrue();
140-
this.writer.setPolicyDirectives(DEFAULT_POLICY_DIRECTIVES);
141-
assertThat(this.writer.isNonceBased()).isFalse();
142-
this.writer.setPolicyDirectives("script-src 'self' 'sha256-A/nonce/without/braces/is/not/a/placeholder='");
143-
assertThat(this.writer.isNonceBased()).isFalse();
144-
}
145-
146134
@Test
147135
public void writeNonceBasedCspWhenNoncePresent() {
148136
this.writer.setPolicyDirectives("script-src 'nonce-{nonce}'; style-src 'nonce-{nonce}'");

web/src/test/java/org/springframework/security/web/server/header/ContentSecurityPolicyServerHttpHeadersWriterTests.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,6 @@ public void writeHeadersWhenAlreadyWrittenThenDoesNotOverride() {
9696
assertThat(headers.get(CONTENT_SECURITY_POLICY_HEADER)).containsOnly(headerValue);
9797
}
9898

99-
@Test
100-
public void whenPolicyDirectivesContainNoncePlaceholderThenWriterIsNonceBased() {
101-
this.writer.setPolicyDirectives("script-src 'self' 'nonce-{nonce}'");
102-
assertThat(this.writer.isNonceBased()).isTrue();
103-
this.writer.setPolicyDirectives("script-src 'nonce-{nonce}'; style-src 'nonce-{nonce}'");
104-
assertThat(this.writer.isNonceBased()).isTrue();
105-
this.writer.setPolicyDirectives(DEFAULT_POLICY_DIRECTIVES);
106-
assertThat(this.writer.isNonceBased()).isFalse();
107-
this.writer.setPolicyDirectives("script-src 'self' 'sha256-A/nonce/without/braces/is/not/a/placeholder='");
108-
assertThat(this.writer.isNonceBased()).isFalse();
109-
}
110-
11199
@Test
112100
public void writeNonceBasedCspWhenNoncePresent() {
113101
this.writer.setPolicyDirectives("script-src 'nonce-{nonce}'; style-src 'nonce-{nonce}'");

0 commit comments

Comments
 (0)