Compare commits
4 Commits
master
...
rule/modif
Author | SHA1 | Date | |
---|---|---|---|
![]() |
676e7c5bfe | ||
![]() |
054780cf2e | ||
![]() |
8dac0cac06 | ||
![]() |
ce2dc177df |
@ -43,6 +43,7 @@
|
||||
* Jdom2
|
||||
* JSP
|
||||
* Legacy Mongo Java API
|
||||
* Micronaut
|
||||
* OkHttp
|
||||
* Realm
|
||||
* Servlet
|
||||
|
39
rules/S5146/java/how-to-fix-it/micronaut.adoc
Normal file
39
rules/S5146/java/how-to-fix-it/micronaut.adoc
Normal file
@ -0,0 +1,39 @@
|
||||
== How to fix it in Micronaut
|
||||
|
||||
=== Code examples
|
||||
|
||||
include::../../common/fix/code-rationale.adoc[]
|
||||
|
||||
==== Noncompliant code example
|
||||
|
||||
[source,java,diff-id=10,diff-type=noncompliant]
|
||||
----
|
||||
@Get("/Noncompliant/httpresponse")
|
||||
public HttpResponse<String> noncompliant(@QueryValue("q") String location) throws URISyntaxException {
|
||||
URI url = new URI(location);
|
||||
return HttpResponse.redirect(url); // Noncompliant
|
||||
}
|
||||
----
|
||||
|
||||
==== Compliant solution
|
||||
|
||||
[source,java,diff-id=10,diff-type=compliant]
|
||||
----
|
||||
@Get("/Compliant/httpresponse")
|
||||
public HttpResponse<String> compliant(@QueryValue("q") String location) throws URISyntaxException {
|
||||
URI url = new URI(location);
|
||||
String authority = url.getAuthority();
|
||||
if (authority != null && authority.endsWith(".example.com")) {
|
||||
return HttpResponse.redirect(url);
|
||||
} else {
|
||||
return HttpResponse.status(HttpStatus.FORBIDDEN);
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
include::../../common/fix/how-does-this-work.adoc[]
|
||||
|
||||
=== Pitfalls
|
||||
|
||||
include::../../common/pitfalls/starts-with.adoc[]
|
||||
|
@ -8,6 +8,9 @@ include::../impact.adoc[]
|
||||
|
||||
include::how-to-fix-it/java-se.adoc[]
|
||||
|
||||
include::how-to-fix-it/micronaut.adoc[]
|
||||
|
||||
|
||||
== Resources
|
||||
|
||||
include::../common/resources/standards.adoc[]
|
||||
|
Loading…
x
Reference in New Issue
Block a user