Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify rule S5659: Add nimbus sample #3981

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/header_names/allowed_framework_names.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
* Spring Data Redis
* SQLCipher
* Thymeleaf
* Nimbus
// JS
* Flow.js
* Node.js
Expand Down
63 changes: 63 additions & 0 deletions rules/S5659/java/how-to-fix-it/nimbus.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
== How to fix it in Nimbus

=== Code examples

include::../../common/fix/code-rationale.adoc[]

==== Noncompliant code example

[source,java,diff-id=21,diff-type=noncompliant]
----
import com.nimbusds.jwt.PlainJWT;

public void encode(JWTClaimsSet claimsSet) {
PlainJWT jwt = new PlainJWT(claimsSet); // Noncompliant
}
----

[source,java,diff-id=22,diff-type=noncompliant]
----
import com.nimbusds.jwt.PlainJWT;

public void decode(String jwtString) {
PlainJWT jwt = PlainJWT.parse(jwtString); // Noncompliant
}
----

==== Compliant solution

[source,java,diff-id=21,diff-type=compliant]
----
import com.nimbusds.jwt.SignedJWT;

public void encode(JWTClaimsSet claimsSet) {
SignedJWT jwt = new SignedJWT(new JWSHeader(JWSAlgorithm.HS256), claimsSet);
jwt.sign(new MACSigner(sharedSecret));
}
----

[source,java,diff-id=22,diff-type=compliant]
----
import com.nimbusds.jwt.SignedJWT;

public void decode(String jwtString) {
SignedJWT jwt = SignedJWT.parse(jwtString);

if (!jwt.verify(new MACVerifier(sharedSecret))) {
throw new JOSEException("JWT signature does not match");
}
}
----

=== How does this work?

include::../../common/fix/encode.adoc[]

include::../../common/fix/decode.adoc[]

=== Going the extra mile

include::../../common/extra-mile/key-storage.adoc[]

include::../../common/extra-mile/key-rotation.adoc[]

2 changes: 2 additions & 0 deletions rules/S5659/java/rule.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ include::how-to-fix-it/jjwt.adoc[]

include::how-to-fix-it/java-jwt.adoc[]

include::how-to-fix-it/nimbus.adoc[]

== Resources

include::../common/resources/standards.adoc[]
Expand Down