Skip to content

Commit f71a541

Browse files
committed
Add annotations for security headers
1 parent 33e7854 commit f71a541

File tree

9 files changed

+17
-0
lines changed

9 files changed

+17
-0
lines changed

stubbornjava-common/src/main/java/com/stubbornjava/common/undertow/handlers/CustomHandlers.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ public static HttpHandler loadBalancerHttpToHttps(HttpHandler next) {
152152
};
153153
}
154154

155+
// {{start:securityHeaders}}
155156
public static HttpHandler securityHeaders(HttpHandler next, ReferrerPolicy policy) {
156157
MiddlewareBuilder security = MiddlewareBuilder
157158
.begin(XFrameOptionsHandlers::deny)
@@ -166,4 +167,5 @@ public static HttpHandler securityHeaders(HttpHandler next, ReferrerPolicy polic
166167
}
167168
return security.complete(next);
168169
}
170+
// {{end:securityHeaders}}
169171
}

stubbornjava-undertow/src/main/java/com/stubbornjava/undertow/handlers/ContentSecurityPolicyHandler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import io.undertow.server.HttpHandler;
99
import io.undertow.server.handlers.SetHeaderHandler;
1010

11+
// {{start:handler}}
1112
public class ContentSecurityPolicyHandler {
1213
private static final String CSP_HEADER = "Content-Security-Policy";
1314

@@ -193,3 +194,4 @@ private String join(String... strings) {
193194
}
194195
}
195196
}
197+
// {{end:handler}}

stubbornjava-undertow/src/main/java/com/stubbornjava/undertow/handlers/ReferrerPolicyHandlers.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io.undertow.server.HttpHandler;
44
import io.undertow.server.handlers.SetHeaderHandler;
55

6+
// {{start:handler}}
67
public class ReferrerPolicyHandlers {
78
private static final String REFERRER_POLICY_STRING = "Referrer-Policy";
89

@@ -30,3 +31,4 @@ public static HttpHandler policy(HttpHandler next, ReferrerPolicy policy) {
3031
return new SetHeaderHandler(next, REFERRER_POLICY_STRING, policy.getValue());
3132
}
3233
}
34+
// {{end:handler}}

stubbornjava-undertow/src/main/java/com/stubbornjava/undertow/handlers/StrictTransportSecurityHandlers.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import io.undertow.server.handlers.SetHeaderHandler;
55
import io.undertow.util.Headers;
66

7+
// {{start:handler}}
78
public class StrictTransportSecurityHandlers {
89

910
public static HttpHandler hsts(HttpHandler next, long maxAge) {
@@ -14,3 +15,4 @@ public static HttpHandler hstsIncludeSubdomains(HttpHandler next, long maxAge) {
1415
return new SetHeaderHandler(next, Headers.STRICT_TRANSPORT_SECURITY_STRING, "max-age=" + maxAge + "; includeSubDomains");
1516
}
1617
}
18+
// {{end:handler}}

stubbornjava-undertow/src/main/java/com/stubbornjava/undertow/handlers/XContentTypeOptionsHandler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
import io.undertow.server.HttpHandler;
44
import io.undertow.server.handlers.SetHeaderHandler;
55

6+
// {{start:handler}}
67
public class XContentTypeOptionsHandler {
78
private static final String X_CONTENT_TYPE_OPTIONS_STRING = "X-Content-Type-Options";
89

910
public static HttpHandler nosniff(HttpHandler next) {
1011
return new SetHeaderHandler(next, X_CONTENT_TYPE_OPTIONS_STRING, "nosniff");
1112
}
1213
}
14+
// {{end:handler}}

stubbornjava-undertow/src/main/java/com/stubbornjava/undertow/handlers/XFrameOptionsHandlers.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import io.undertow.server.handlers.SetHeaderHandler;
88
import io.undertow.util.HttpString;
99

10+
// {{start:handler}}
1011
public class XFrameOptionsHandlers {
1112
private static final String X_FRAME_OPTIONS_STRING = "X-Frame-Options";
1213
private static final HttpString X_FRAME_OPTIONS = new HttpString(X_FRAME_OPTIONS_STRING);
@@ -32,3 +33,4 @@ public static HttpHandler allowFromDynamicOrigin(HttpHandler next,
3233
};
3334
}
3435
}
36+
// {{end:handler}}

stubbornjava-undertow/src/main/java/com/stubbornjava/undertow/handlers/XXssProtectionHandlers.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io.undertow.server.HttpHandler;
44
import io.undertow.server.handlers.SetHeaderHandler;
55

6+
// {{start:handler}}
67
public class XXssProtectionHandlers {
78
private static final String X_XSS_PROTECTION_STRING = "X-Xss-Protection";
89

@@ -18,3 +19,4 @@ public static HttpHandler enableAndBlock(HttpHandler next) {
1819
return new SetHeaderHandler(next, X_XSS_PROTECTION_STRING, "1; mode=block");
1920
}
2021
}
22+
// {{end:handler}}

stubbornjava-webapp/src/main/java/com/stubbornjava/webapp/StubbornJavaWebApp.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ private static HttpHandler exceptionHandler(HttpHandler next) {
3333
.addExceptionHandler(Throwable.class, PageRoutes::error);
3434
}
3535

36+
// {{start:csp}}
3637
private static HttpHandler contentSecurityPolicy(HttpHandler delegate) {
3738
return new ContentSecurityPolicyHandler.Builder()
3839
.defaultSrc(ContentSecurityPolicy.SELF)
@@ -44,6 +45,7 @@ private static HttpHandler contentSecurityPolicy(HttpHandler delegate) {
4445
.styleSrc(ContentSecurityPolicy.SELF.getValue(), ContentSecurityPolicy.UNSAFE_INLINE.getValue())
4546
.build(delegate);
4647
}
48+
// {{end:csp}}
4749

4850
private static HttpHandler wrapWithMiddleware(HttpHandler next) {
4951
return MiddlewareBuilder.begin(PageRoutes::redirector)

stubbornjava-webapp/src/main/java/com/stubbornjava/webapp/post/Tags.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class Tags {
3030
public static final Tag Elasticsearch = addTag(new Tag(922794262770139008L, "Elasticsearch"));
3131
public static final Tag Ansible = addTag(new Tag(922794262770139008L, "Ansible"));
3232
public static final Tag Supervisord = addTag(new Tag(922794262770139008L, "Supervisord"));
33+
public static final Tag Security = addTag(new Tag(953801444178362856L, "Security"));
3334

3435
private static Tag addTag(Tag tag) {
3536
TAGS.add(tag);

0 commit comments

Comments
 (0)