Skip to content

Commit

Permalink
fix: amélioration de token max length
Browse files Browse the repository at this point in the history
  • Loading branch information
remy-auricoste committed Nov 23, 2023
1 parent 5fb6b02 commit 77056af
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions server/src/security/accessTokenService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ import { AnyZodObject, z } from "zod"
import { sentryCaptureException } from "@/common/utils/sentryUtils"
import config from "@/config"

// cf https://www.sistrix.com/ask-sistrix/technical-seo/site-structure/url-length-how-long-can-a-url-be
const INTERNET_EXPLORER_V10_MAX_LENGTH = 2083
const OUTLOOK_URL_MAX_LENGTH = 2048
const URL_MAX_LENGTH = Math.min(INTERNET_EXPLORER_V10_MAX_LENGTH, OUTLOOK_URL_MAX_LENGTH)
const OUTLOOK_URL_MAX_LENGTH = 8192
const NGINX_URL_MAX_LENGTH = 4096
const URL_MAX_LENGTH = Math.min(INTERNET_EXPLORER_V10_MAX_LENGTH, OUTLOOK_URL_MAX_LENGTH, NGINX_URL_MAX_LENGTH)
const TOKEN_MAX_LENGTH = URL_MAX_LENGTH - "https://labonnealternance.apprentissage.beta.gouv.fr/".length

type SchemaWithSecurity = Pick<IRouteSchema, "method" | "path" | "params" | "querystring"> & WithSecurityScheme

Expand Down Expand Up @@ -95,7 +98,7 @@ export function generateAccessToken(
expiresIn: options.expiresIn ?? config.auth.user.expiresIn,
issuer: config.publicUrl,
})
if (token.length > URL_MAX_LENGTH) {
if (token.length > TOKEN_MAX_LENGTH) {
sentryCaptureException(Boom.internal(`Token généré trop long : ${token.length}`))
}
return token
Expand Down

0 comments on commit 77056af

Please sign in to comment.