Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Ilya Vysotski
Koa Shopify Auth
Commits
7b28baf3
Commit
7b28baf3
authored
Oct 01, 2020
by
Anthony Morris
Browse files
Return false as early as possible
parent
c5433ae2
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/auth/safe-compare.ts
View file @
7b28baf3
...
...
@@ -4,11 +4,15 @@ export default function safeCompare(stringA: string, stringB: string) {
const
aLen
=
Buffer
.
byteLength
(
stringA
);
const
bLen
=
Buffer
.
byteLength
(
stringB
);
if
(
aLen
!==
bLen
)
{
return
false
}
// Turn strings into buffers with equal length
// to avoid leaking the length
const
buffA
=
Buffer
.
alloc
(
aLen
,
0
,
'
utf8
'
);
buffA
.
write
(
stringA
);
const
buffB
=
Buffer
.
alloc
(
a
Len
,
0
,
'
utf8
'
);
const
buffB
=
Buffer
.
alloc
(
b
Len
,
0
,
'
utf8
'
);
buffB
.
write
(
stringB
);
return
crypto
.
timingSafeEqual
(
buffA
,
buffB
)
&&
aLen
===
bLen
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment