From aea5f4af5bc35f50349ed9149bc9bb757121c0e3 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Fri, 19 Jul 2024 08:38:48 +0100 Subject: [PATCH 1/2] refactor(index): use `i` case-insensitive flag over character ranges --- index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index b48a33d..5c87fe3 100644 --- a/index.js +++ b/index.js @@ -22,7 +22,7 @@ const MissingOrBadAuthorizationHeader = createError( * The scheme name is "Basic". * @see https://datatracker.ietf.org/doc/html/rfc7617#section-2 */ -const authScheme = '(?:[Bb][Aa][Ss][Ii][Cc])' +const authScheme = '(?:basic)' /** * The BWS rule is used where the grammar allows optional whitespace * only for historical reasons. A sender MUST NOT generate BWS in @@ -40,14 +40,14 @@ const BWS = '[ \t]' * ([RFC4648]). * @see https://datatracker.ietf.org/doc/html/rfc7235#section-2.1 */ -const token68 = '([A-Za-z0-9._~+/-]+=*)' +const token68 = '([a-z0-9._~+/-]+=*)' /** * @see https://datatracker.ietf.org/doc/html/rfc7235#appendix-C */ -const credentialsStrictRE = new RegExp(`^${authScheme} ${token68}$`) +const credentialsStrictRE = new RegExp(`^${authScheme} ${token68}$`, 'i') -const credentialsLaxRE = new RegExp(`^${BWS}*${authScheme}${BWS}+${token68}${BWS}*$`) +const credentialsLaxRE = new RegExp(`^${BWS}*${authScheme}${BWS}+${token68}${BWS}*$`, 'i') /** * @see https://datatracker.ietf.org/doc/html/rfc5234#appendix-B.1 From e66e19e1695e147b9c929feabfa60133984a954d Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Fri, 19 Jul 2024 08:39:42 +0100 Subject: [PATCH 2/2] refactor(index): use word character inside regex character class --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 5c87fe3..dec9189 100644 --- a/index.js +++ b/index.js @@ -40,7 +40,7 @@ const BWS = '[ \t]' * ([RFC4648]). * @see https://datatracker.ietf.org/doc/html/rfc7235#section-2.1 */ -const token68 = '([a-z0-9._~+/-]+=*)' +const token68 = '([\\w.~+/-]+=*)' /** * @see https://datatracker.ietf.org/doc/html/rfc7235#appendix-C