Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions ext/node/polyfills/_tls_common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ function validateKeyCertOption(
);
}

const secureContextBrand = new WeakSet<object>();

export class SecureContext {
context: {
ca?: string | string[];
Expand Down Expand Up @@ -199,6 +201,22 @@ export class SecureContext {
sigalgs: options.sigalgs,
ecdhCurve: options.ecdhCurve,
};
secureContextBrand.add(this.context);
Object.defineProperty(this.context, "_external", {
__proto__: null,
configurable: true,
enumerable: false,
get(this: object) {
// In Node, `_external` is the C++ external pointer; reading it on a
// non-context receiver hits an internal slot check and throws. Match
// that behaviour so prototype-tampering tests don't get a silent
// undefined.
if (!secureContextBrand.has(this)) {
throw new TypeError("Illegal invocation");
}
return this;
},
});
}

// Backward compat: current _tls_wrap.js accesses .ca, .cert, .key directly
Expand Down
1 change: 1 addition & 0 deletions tests/node_compat/config.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -3066,6 +3066,7 @@
"parallel/test-tls-enable-trace-cli.js": {},
"parallel/test-tls-enable-trace.js": {},
"parallel/test-tls-env-extra-ca-no-crypto.js": {},
"parallel/test-tls-external-accessor.js": {},
"parallel/test-tls-fast-writing.js": {},
"parallel/test-tls-finished.js": {},
"parallel/test-tls-friendly-error-message.js": {},
Expand Down
Loading