Skip to content

tls.SecureContext documentation contradictions #47408

Description

@shollander

Affected URL(s)

https://nodejs.org/api/tls.html#tlscreatesecurecontextoptions
https://nodejs.org/api/tls.html#serveraddcontexthostname-context

Description of the problem

The documentation for tls.createSecureContext() states:

The tls.createSecureContext() method creates a SecureContext object. It is usable as an argument to several tls APIs, such as server.addContext(), but has no public methods. The tls.Server constructor and the tls.createServer() method do not support the secureContext option.

So according to the documentation, server.addContext() should take a SecureContext object as an argument. However, according to the documention of server.addContext(), the only valid argument for options is SecureContextOptions, but not the SecureContext object itself.

I have tried passing a SecureContext object to server.addContext(). While it did not throw any errors, it did not configure the secure context properly.

It would really be nice if server.addContext() would take a SecureContext object. Ideally, you should fix the code and update the documentation for server.addContext().

Thank you.

Activity

  1. added
    docIssues and PRs related to Node.js documentation.
    on Apr 4, 2023
  2. bnoordhuis commented on Apr 4, 2023

    @bnoordhuis
    Member

    Pull request welcome. You can check inside addContext() if the context argument is already instanceof SecureContext and then use context.context instead of passing context to tls.createSecureContext():

    node/lib/_tls_wrap.js

    Lines 1479 to 1480 in 6fd147c

    ArrayPrototypePush(this._contexts,
    [re, tls.createSecureContext(context).context]);

  3. added
    tlsIssues and PRs related to the tls subsystem.
    feature requestIssues requesting new Node.js features.
    and removed
    docIssues and PRs related to Node.js documentation.
    on Apr 4, 2023
  4. shollander commented on Apr 4, 2023

    @shollander
    Author

    Seems like a relatively simple change. Unfortunately, I don't have an environment where I can readily build and test node.js.

  5. HinataKah0 commented on Apr 6, 2023

    @HinataKah0
    Contributor

    If you want to try, you can refer to this for building Node JS locally.

  6. moved this from Awaiting Triage to Done in Node.js feature requestson Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues requesting new Node.js features.tlsIssues and PRs related to the tls subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions