mirror of
https://github.com/morluto/rea.git
synced 2026-12-07 06:33:04 +08:00
fix(javascript): omit effects refused by host construction (#11122)
Filter child-process, fetch/WebSocket and TLS effects for literal calls the host refuses to construct. Share copied child options across validation and projection, preserving uncertainty from own and inherited getters. Includes the original implementations from #10528, #10529 and #10530. Validation: 394 domain/public CLI/MCP tests, then 54 request/public tests after the review correction, static checks and discovery passed. Also verified 29 Node 24.22.1 probes and actual Chromium 156 header/Request constructors. Full browser app/network behavior was not tested. Analysis does not execute target source. Fixes #10522 Fixes #10523 Fixes #10524 Related: #10528, #10529, #10530 Co-authored-by: RRFZ <247457381+Plastic-time@users.noreply.github.com> Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
This commit is contained in:
co-authored by
RRFZ
gensokyo-dev
parent
6363881faa
commit
44d359bd05
@@ -907,7 +907,70 @@ const rejectsTlsProtocolVersionLiteral = (
|
||||
if (read === undefined || read === "unknown") continue;
|
||||
if (rejectsValue(read)) return true;
|
||||
}
|
||||
return false;
|
||||
return rejectsSecureProtocolLiteral(effective, state);
|
||||
};
|
||||
|
||||
/**
|
||||
* The `secureProtocol` method names Node accepts. Measured on Node 24.22.1, these
|
||||
* connect while `"SSLv2_method"`, `"SSLv3_method"` and their client/server forms,
|
||||
* `"TLSv1_3_method"`, `"DTLS_method"`, `"tls_method"`, `"TLS_METHOD"`, `"bogus"`
|
||||
* and `""` throw `ERR_TLS_INVALID_PROTOCOL_METHOD`. The set is exact and
|
||||
* case-sensitive.
|
||||
*/
|
||||
const TLS_SECURE_PROTOCOLS = new Set(
|
||||
["TLS", "TLSv1", "TLSv1_1", "TLSv1_2", "SSLv23"].flatMap((family) => [
|
||||
`${family}_method`,
|
||||
`${family}_client_method`,
|
||||
`${family}_server_method`,
|
||||
]),
|
||||
);
|
||||
|
||||
/**
|
||||
* Whether `secureProtocol` makes `tls.connect` throw before a socket exists.
|
||||
*
|
||||
* Measured on Node 24.22.1, after the same truthy-`secureContext` bypass as the
|
||||
* version members:
|
||||
*
|
||||
* a string outside TLS_SECURE_PROTOCOLS, including "" -> THREW ERR_TLS_INVALID_PROTOCOL_METHOD
|
||||
* a non-string value such as 5, true or {} -> socket (Node ignores it)
|
||||
* a truthy value beside a minVersion or maxVersion that
|
||||
* is not null or undefined, even "TLS_method" -> THREW ERR_TLS_PROTOCOL_VERSION_CONFLICT
|
||||
* "TLS_method" beside a null or undefined version -> socket
|
||||
* 0 beside a minVersion -> socket
|
||||
*/
|
||||
const rejectsSecureProtocolLiteral = (
|
||||
effective: (member: string) => t.Node | "unknown" | undefined,
|
||||
state: JavaScriptSemanticAnalysisState,
|
||||
): boolean => {
|
||||
const protocol = effective("secureProtocol");
|
||||
if (protocol === undefined || protocol === "unknown") return false;
|
||||
const read = unwrapJavaScriptExpression(protocol).node;
|
||||
if (isNullishPlaceholder(read, state)) return false;
|
||||
const literal = readExactJavaScriptLiteral(read);
|
||||
if (
|
||||
literal.found &&
|
||||
typeof literal.value === "string" &&
|
||||
!TLS_SECURE_PROTOCOLS.has(literal.value)
|
||||
)
|
||||
return true;
|
||||
// A literal read exactly, including a no-substitution template, decides its own
|
||||
// truthiness; the shared truthiness reader does not price templates.
|
||||
const truthy = literal.found
|
||||
? Boolean(literal.value)
|
||||
: staticJavaScriptTruthiness(read);
|
||||
if (truthy !== true) return false;
|
||||
return (["minVersion", "maxVersion"] as const).some((member) => {
|
||||
const version = effective(member);
|
||||
if (version === undefined || version === "unknown") return false;
|
||||
const value = unwrapJavaScriptExpression(version).node;
|
||||
return (
|
||||
!isNullishPlaceholder(value, state) &&
|
||||
(readExactJavaScriptLiteral(value).found ||
|
||||
t.isTemplateLiteral(value) ||
|
||||
t.isObjectExpression(value) ||
|
||||
t.isArrayExpression(value))
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user