src: make Sec-WebSocket-Key check case-insensitive · nodejs/node@3d69ad1 · GitHub
Skip to content

Commit 3d69ad1

Browse files
MylesBorinsFishrock123
authored andcommitted
src: make Sec-WebSocket-Key check case-insensitive
Current case sensitive comparison is breaking netty-based WS clients. replace strncmp with strncasecmp Fixes: #7247 PR-URL: #7248 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent 88b2aa3 commit 3d69ad1

4 files changed

Lines changed: 34 additions & 3 deletions

File tree

src/inspector_socket.cc

Lines changed: 6 additions & 3 deletions

src/util-inl.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,16 @@ bool StringEqualNoCase(const char* a, const char* b) {
219219
return false;
220220
}
221221

222+
bool StringEqualNoCaseN(const char* a, const char* b, size_t length) {
223+
for (size_t i = 0; i < length; i++) {
224+
if (ToLower(a[i]) != ToLower(b[i]))
225+
return false;
226+
if (a[i] == '\0')
227+
return true;
228+
}
229+
return true;
230+
}
231+
222232
} // namespace node
223233

224234
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

src/util.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ inline char ToLower(char c);
206206
// strcasecmp() is locale-sensitive. Use StringEqualNoCase() instead.
207207
inline bool StringEqualNoCase(const char* a, const char* b);
208208

209+
// strncasecmp() is locale-sensitive. Use StringEqualNoCaseN() instead.
210+
inline bool StringEqualNoCaseN(const char* a, const char* b, size_t length);
211+
209212
// Allocates an array of member type T. For up to kStackStorageSize items,
210213
// the stack is used, otherwise malloc().
211214
template <typename T, size_t kStackStorageSize = 1024>

test/cctest/util.cc

Lines changed: 15 additions & 0 deletions

0 commit comments

Comments
 (0)