fix: ctype UB, WebSocket over-read, stoi crash, signed shift UB, proto pollution - #65763
fix: ctype UB, WebSocket over-read, stoi crash, signed shift UB, proto pollution#65763VirajMishra1 wants to merge 1 commit into
Conversation
|
Review requested:
|
|
Caution AgentScan found account activity patterns that may be consistent with |
61336d0 to
ce98e53
Compare
|
Please make sure you have read and understood the following documents: |
|
I have read and understood all of the linked documents -- the contributing guide, pull request guide, AI use policy, automation policy, and Code of Conduct. To be transparent: I used AI tooling to help identify these bugs and draft the initial code, but I personally reviewed each change, understand what it does, and take responsibility for it. I did not use automated tooling to open this PR -- I opened it manually after reviewing the diff. Happy to discuss any of the specific changes if that would help. |
ce98e53 to
ab3faa4
Compare
|
Please check the CI failures for your PR. You can view them under https://github.com/nodejs/node/actions?query=actor%3AVirajMishra1+is%3Afailure You should make sure that your changes run successfully locally. See https://github.com/nodejs/node/blob/main/doc/contributing/pull-requests.md#step-6-test |
ab3faa4 to
669354e
Compare
- inspector_io.cc: cast to unsigned char before ::isdigit (UB on signed char)
- inspector_io.cc: use std::from_chars instead of std::stoi (no exceptions)
- inspector_io.cc: cast to unsigned int before <<16 (signed shift UB)
- inspector_socket.cc: fix WebSocket frame bounds using buffer.end()-it
- _http_outgoing.js: use {__proto__:null} in _renderHeaders (prototype pollution)
- os.js: use {__proto__:null} in networkInterfaces (prototype pollution)
Signed-off-by: VirajMishra1 <viraj.mishra.81@gmail.com>
669354e to
9d651d8
Compare
|
Thanks for checking. Two CI failures, both now fixed:
Force-pushed the updated commit. CI should be clean now. |
fix: ctype UB, WebSocket over-read, stoi crash, shift UB, proto pollution
Six correctness and safety fixes across four files:
1. src/inspector_io.cc:381 -- isdigit called on plain char (undefined behavior)
::isdigitis defined only for values representable as unsigned char or EOF.Passing a plain char (which may be negative on platforms where char is signed)
is undefined behavior. Fixed with an (unsigned char) cast in the lambda.
2. src/inspector_socket.cc:363 -- WebSocket extended-frame buffer over-read
The extended-payload-length bounds check used
buffer.size() - kMaskingKeyWidthInBytesas the minimum remaining bytes, but
bufferis the full original buffer whileitmay already have advanced into it. On a crafted extended-length frame,payload_lengthbytes could be read past the end of the available data.Fixed to check
buffer.end() - it(remaining bytes from current position).3. src/inspector_io.cc:383 -- std::stoi throws on out-of-range port strings
std::stoithrowsstd::out_of_rangefor digit-only strings that exceed INT_MAX(e.g. "99999999999" passes the isdigit check but crashes). Added
try/catch (std::exception&)to handle bothinvalid_argumentandout_of_range.4. src/inspector_io.cc:386 -- signed left shift is undefined behavior
target_session_id << 16on a signed int is UB if the result overflows.Fixed with
static_cast<unsigned int>(target_session_id) << 16.5. lib/_http_outgoing.js:287 -- prototype-inheriting header dict
const headers = {}in_renderHeaders()creates an object that inheritsfrom Object.prototype. Header names are user-controlled strings; a header named
__proto__ortoStringcan shadow prototype properties.Fixed to
{ __proto__: null }.6. lib/os.js:219 -- prototype-inheriting network interface dict
Same issue in
networkInterfaces(): the result object is keyed by OS interfacenames. Fixed to
{ __proto__: null }.