Compare commits

...

4 Commits

Author SHA1 Message Date
gaetan-ferry-sonarsource
676e7c5bfe
Fix typo
Co-authored-by: daniel-teuchert-sonarsource <141642369+daniel-teuchert-sonarsource@users.noreply.github.com>
2024-06-06 16:23:10 +02:00
Gaëtan Ferry
054780cf2e Fix issue with code examples/ 2024-06-06 15:52:11 +02:00
Gaëtan Ferry
8dac0cac06 Fix wrong diff-id 2024-06-04 16:34:31 +02:00
Gaëtan Ferry
ce2dc177df Adding education content for Micronaut 2024-06-04 16:32:49 +02:00
3 changed files with 43 additions and 0 deletions

View File

@ -43,6 +43,7 @@
* Jdom2 * Jdom2
* JSP * JSP
* Legacy Mongo Java API * Legacy Mongo Java API
* Micronaut
* OkHttp * OkHttp
* Realm * Realm
* Servlet * Servlet

View 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[]

View File

@ -8,6 +8,9 @@ include::../impact.adoc[]
include::how-to-fix-it/java-se.adoc[] include::how-to-fix-it/java-se.adoc[]
include::how-to-fix-it/micronaut.adoc[]
== Resources == Resources
include::../common/resources/standards.adoc[] include::../common/resources/standards.adoc[]