2020-06-30 12:50:28 +02:00
include::../description.adoc[]
== Noncompliant Code Example
https://www.npmjs.com/package/jsonwebtoken[jsonwebtoken] library:
2020-06-30 14:49:38 +02:00
2020-06-30 12:50:28 +02:00
----
const jwt = require('jsonwebtoken');
2020-12-21 15:38:52 +01:00
let token = jwt.sign({ foo: 'bar' }, key, { algorithm: 'none' }); // Noncompliant: 'none' cipher doesn't sign the JWT (no signature will be included)
2020-06-30 12:50:28 +02:00
2020-12-21 15:38:52 +01:00
jwt.verify(token, key, { expiresIn: 360000 * 5, algorithms: ['RS256', 'none'] }, callbackcheck); // Noncompliant: 'none' cipher should not be used when verifying JWT signature
2020-06-30 12:50:28 +02:00
----
== Compliant Solution
https://www.npmjs.com/package/jsonwebtoken[jsonwebtoken] library:
2020-06-30 14:49:38 +02:00
2020-06-30 12:50:28 +02:00
----
const jwt = require('jsonwebtoken');
let token = jwt.sign({ foo: 'bar' }, key, { algorithm: 'HS256' }); // Compliant
jwt.verify(token, key, { expiresIn: 360000 * 5, algorithms: ['HS256'] }, callbackcheck); // Compliant
----
include::../see.adoc[]
2021-06-02 20:44:38 +02:00
2021-06-03 09:05:38 +02:00
ifdef::env-github,rspecator-view[]
2021-06-08 15:52:13 +02:00
'''
2021-06-02 20:44:38 +02:00
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
2021-06-03 09:05:38 +02:00
endif::env-github,rspecator-view[]