GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — tls: throw on invalid ALPNProtocols instead of aborting by sankalpsthakur · Pull Request #65076 · nodejs/node

Conversation

@sankalpsthakur

@sankalpsthakur sankalpsthakur commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Fixes #65069

tls.connect() with malformed ALPNProtocols (e.g. [''] or invalid wire format buffers like Buffer.from([0])) aborts the process with SIGABRT. The failure is CHECK_EQ(0, SSL_set_alpn_protos(...)) in TLSWrap::SetALPNProtocols when OpenSSL rejects the malformed list.

This change replaces the hard abort with THROW_ERR_INVALID_ARG_VALUE so invalid input throws a recoverable JavaScript exception. Valid inputs are unchanged; e.g. ['h2','http/1.1'] and wire buffers produced by convertProtocols continue to work.

Repro: node -e "require('node:tls').connect({ host: '127.0.0.1', port: 9999, ALPNProtocols: [''] })"

Before: SIGABRT exit 134
After: throws ERR_INVALID_ARG_VALUE

Assisted-by: Codex

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@nodejs-github-bot

nodejs-github-bot commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/crypto
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. crypto Issues and PRs related to the crypto subsystem. needs-ci PRs that need a full CI run. labels Aug 6, 2026
pimterry
pimterry requested changes Aug 6, 2026
View reviewed changes

@pimterry pimterry left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking at this @sankalpsthakur! I agree it'd be good to fix, but I think there's a different approach that would cover the server case too and be a bit cleaner.

We do also need a test covering this, either as a new test or extending any existing validation tests we have here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/crypto/crypto_tls.cc Resolved

Uh oh!

There was an error while loading. Please reload this page.

sankalpsthakur pushed a commit to sankalpsthakur/node that referenced this pull request Aug 6, 2026
sankalpsthakur
tls: validate ALPNProtocols in JS and cover server case
bc50a18
Address review feedback on nodejs#65076: move validation closer to call
site in convertALPNProtocols so both client and server are covered
and fail early. Empty string protocols now throw before reaching
OpenSSL; wire-format buffers are validated for truncated/zero-length
entries. C++ defense (THROW_ERR_INVALID_ARG_VALUE) remains for safety.

Refs: nodejs#65076
sankalpsthakur pushed a commit to sankalpsthakur/node that referenced this pull request Aug 6, 2026
sankalpsthakur
test: add validation for invalid ALPNProtocols
dab0602
Refs: nodejs#65069
PR-URL: nodejs#65076
@sankalpsthakur

sankalpsthakur commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

Updated per review: validation now in lib/tls.js convertALPNProtocols (covers client and server, fails early), C++ defense kept, added test covering [''] and malformed buffers (Buffer.from([0]), [2,0x61], [1,0x61,0x62]). Ready for re-review.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

sankalpsthakur pushed a commit to sankalpsthakur/node that referenced this pull request Aug 6, 2026
sankalpsthakur
tls: validate ALPNProtocols in JS and cover server case
9b9eaca
Address review feedback on nodejs#65076: move validation closer to call
site in convertALPNProtocols so both client and server are covered
and fail early. Empty string protocols now throw before reaching
OpenSSL; wire-format buffers are validated for truncated/zero-length
entries. C++ defense (THROW_ERR_INVALID_ARG_VALUE) remains for safety.

Refs: nodejs#65076
sankalpsthakur pushed a commit to sankalpsthakur/node that referenced this pull request Aug 6, 2026
sankalpsthakur
test: add validation for invalid ALPNProtocols
aac5713
Refs: nodejs#65069
PR-URL: nodejs#65076
@sankalpsthakur
sankalpsthakur force-pushed the fix/65069-alpn-sigabrt branch from dab0602 to af6b21f Compare August 6, 2026 12:42
@sankalpsthakur

sankalpsthakur commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback. I moved validation into convertALPNProtocols so both client and server fail early before reaching OpenSSL, and kept the C++ check as a defense in depth. Empty string protocols now throw via convertProtocols and wire format buffers are validated for empty, zero length and truncated cases. Added test coverage for the repro cases from #65069. I fixed the lint and formatting issues as well and rebased onto latest main.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

pimterry
pimterry requested changes Aug 6, 2026
View reviewed changes
Comment thread lib/tls.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/crypto/crypto_tls.cc Resolved

Uh oh!

There was an error while loading. Please reload this page.

@sankalpsthakur

sankalpsthakur commented Aug 7, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

@pimterry empty [] / empty buffer allowed again (skip ALPN). C++ is CHECK_EQ again, no user throw there. still reject [''] and bad wire buffers in convertALPNProtocols. 6e497bb.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

sankalpsthakur added a commit to sankalpsthakur/node that referenced this pull request Aug 7, 2026
@sankalpsthakur
tls: allow empty ALPNProtocols and keep C++ CHECK_EQ
6e497bb
Empty ALPN buffer/array means skip ALPN (same as historical
behavior for []). Zero-length protocol entries and malformed
wire buffers still throw from convertALPNProtocols.

Revert the C++ THROW_ERR_INVALID_ARG_VALUE back to CHECK_EQ:
after JS validation, a non-zero SSL_set_alpn_protos return is
an internal invariant failure, not user-facing input.

Refs: nodejs#65076
@sankalpsthakur

sankalpsthakur commented Aug 8, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

@pimterry empty ALPN skip, convertALPNProtocols validation, CHECK_EQ, and tests are on latest head. Ready when you have a moment.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jasnell
jasnell approved these changes Aug 8, 2026
View reviewed changes
pimterry
pimterry approved these changes Aug 9, 2026
View reviewed changes
@pimterry pimterry added author ready PRs with CI started, the required approvals, and no outstanding review comments. request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. labels Aug 9, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Aug 9, 2026
@nodejs-github-bot

nodejs-github-bot commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/75694/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sankalpsthakur

sankalpsthakur commented Aug 9, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

CI job 75694 ran on 6e497bb before the fixture fix. That commit still used invalid ALPN bytes (abcd) in test-tls-basic-validations.js, so the reds there are expected.

193e77b uses valid length-prefixed fixtures (same copy-isolation check). Could someone re-run CI on current HEAD? Thanks.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@codecov

codecov Bot commented Aug 9, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.14%. Comparing base (a48e33f) to head (e074e05).
⚠️ Report is 54 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #65076      +/-   ##
==========================================
+ Coverage   90.12%   90.14%   +0.01%     
==========================================
  Files         751      751              
  Lines      252425   252625     +200     
  Branches    47471    47542      +71     
==========================================
+ Hits       227504   227724     +220     
+ Misses      16216    16200      -16     
+ Partials     8705     8701       -4     
Files with missing lines Coverage Δ
lib/tls.js 93.47% <100.00%> (+0.36%) ⬆️

... and 56 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pimterry pimterry added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Aug 9, 2026
@sankalpsthakur
sankalpsthakur force-pushed the fix/65069-alpn-sigabrt branch from 82aed18 to 193e77b Compare August 18, 2026 04:45
@trivikr trivikr removed the author ready PRs with CI started, the required approvals, and no outstanding review comments. label Aug 22, 2026
@trivikr

trivikr commented Aug 22, 2026

Copy link
Copy Markdown
Member

@sankalpsthakur Can you please rebase?

The merge commits don't work with our tooling.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sankalpsthakur
sankalpsthakur force-pushed the fix/65069-alpn-sigabrt branch from 82aed18 to 1e49721 Compare August 22, 2026 07:21
sankalpsthakur pushed a commit to sankalpsthakur/node that referenced this pull request Aug 22, 2026
sankalpsthakur @sankalpsthakur
tls: validate ALPNProtocols in JS and cover server case
d3e359f
Address review feedback on nodejs#65076: move validation closer to call
site in convertALPNProtocols so both client and server are covered
and fail early. Empty string protocols now throw before reaching
OpenSSL; wire-format buffers are validated for truncated/zero-length
entries. C++ defense (THROW_ERR_INVALID_ARG_VALUE) remains for safety.

Refs: nodejs#65076
sankalpsthakur pushed a commit to sankalpsthakur/node that referenced this pull request Aug 22, 2026
sankalpsthakur @sankalpsthakur
test: add validation for invalid ALPNProtocols
6f951ae
Refs: nodejs#65069
PR-URL: nodejs#65076
sankalpsthakur added a commit to sankalpsthakur/node that referenced this pull request Aug 22, 2026
@sankalpsthakur
tls: allow empty ALPNProtocols and keep C++ CHECK_EQ
9a83a24
Empty ALPN buffer/array means skip ALPN (same as historical
behavior for []). Zero-length protocol entries and malformed
wire buffers still throw from convertALPNProtocols.

Revert the C++ THROW_ERR_INVALID_ARG_VALUE back to CHECK_EQ:
after JS validation, a non-zero SSL_set_alpn_protos return is
an internal invariant failure, not user-facing input.

Refs: nodejs#65076
@sankalpsthakur

sankalpsthakur commented Aug 22, 2026

Copy link
Copy Markdown
Contributor Author

rebased onto main (a48e33f), merge commit dropped, six commits linear now. diff is unchanged: lib/tls.js and the two tls tests.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sankalpsthakur
sankalpsthakur force-pushed the fix/65069-alpn-sigabrt branch from 1e49721 to eaaedf8 Compare August 22, 2026 07:25
@sankalpsthakur

sankalpsthakur commented Aug 22, 2026

Copy link
Copy Markdown
Contributor Author

correction to my last note: squashed to a single commit (eaaedf8) rather than the six i mentioned, message rewritten to describe the final js-only validation since the earlier ones still described the reverted c++ change. diff is unchanged.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@trivikr

trivikr commented Aug 22, 2026

Copy link
Copy Markdown
Member

@sankalpsthakur Can you please sign the commit?

It's required as per instructions

Your commit must contain the Signed-off-by line with your name and email address as an acknowledgement that you agree to the Developer Certificate of Origin.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sankalpsthakur
sankalpsthakur force-pushed the fix/65069-alpn-sigabrt branch 3 times, most recently from 73e91cb to 4e001a7 Compare August 23, 2026 04:58
@sankalpsthakur
tls: throw on invalid ALPNProtocols instead of aborting
e074e05
tls.connect() with malformed ALPNProtocols hit
CHECK_EQ(0, SSL_set_alpn_protos(...)) in the C++ layer and aborted
the process with SIGABRT.

Validate in JS instead, in convertALPNProtocols, so both client and
server fail early with a recoverable ERR_INVALID_ARG_VALUE:

- zero-length string protocols now throw from convertProtocols
- wire-format buffers are checked for zero-length and truncated
  entries
- an empty buffer or array is still accepted and means skip ALPN,
  matching the historical behavior for []

The C++ CHECK_EQ is left unchanged: once JS has validated the input,
a non-zero SSL_set_alpn_protos return is an internal invariant
failure rather than user-facing input.

Fixes: nodejs#65069

Signed-off-by: Sankalp Thakur <[email protected]>
@sankalpsthakur
sankalpsthakur force-pushed the fix/65069-alpn-sigabrt branch from 4e001a7 to e074e05 Compare August 23, 2026 04:59
@sankalpsthakur

sankalpsthakur commented Aug 23, 2026

Copy link
Copy Markdown
Contributor Author

Signed-off-by is on e074e05, author Sankalp Thakur [email protected].

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

trivikr
trivikr approved these changes Aug 23, 2026
View reviewed changes
@trivikr trivikr added the author ready PRs with CI started, the required approvals, and no outstanding review comments. label Aug 23, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Aug 23, 2026
@nodejs-github-bot

nodejs-github-bot commented Aug 23, 2026

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/76313/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

pimterry
pimterry approved these changes Aug 24, 2026
View reviewed changes
@nodejs-github-bot

nodejs-github-bot commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/76361/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@trivikr trivikr added the commit-queue PRs queued for automated landing through the Commit Queue. label Aug 24, 2026
@nodejs-github-bot
nodejs-github-bot merged commit 278ead1 into nodejs:main Aug 24, 2026
72 of 73 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot

nodejs-github-bot commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

Landed in 278ead1

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label Aug 24, 2026
aduh95 pushed a commit that referenced this pull request Aug 25, 2026
@sankalpsthakur @aduh95
tls: throw on invalid ALPNProtocols instead of aborting
8ec268f
tls.connect() with malformed ALPNProtocols hit
CHECK_EQ(0, SSL_set_alpn_protos(...)) in the C++ layer and aborted
the process with SIGABRT.

Validate in JS instead, in convertALPNProtocols, so both client and
server fail early with a recoverable ERR_INVALID_ARG_VALUE:

- zero-length string protocols now throw from convertProtocols
- wire-format buffers are checked for zero-length and truncated
  entries
- an empty buffer or array is still accepted and means skip ALPN,
  matching the historical behavior for []

The C++ CHECK_EQ is left unchanged: once JS has validated the input,
a non-zero SSL_set_alpn_protos return is an internal invariant
failure rather than user-facing input.

Fixes: #65069

Signed-off-by: Sankalp Thakur <[email protected]>
PR-URL: #65076
Reviewed-By: Tim Perry <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
aduh95 pushed a commit that referenced this pull request Aug 25, 2026
@sankalpsthakur @aduh95
tls: throw on invalid ALPNProtocols instead of aborting
2a0b1ec
tls.connect() with malformed ALPNProtocols hit
CHECK_EQ(0, SSL_set_alpn_protos(...)) in the C++ layer and aborted
the process with SIGABRT.

Validate in JS instead, in convertALPNProtocols, so both client and
server fail early with a recoverable ERR_INVALID_ARG_VALUE:

- zero-length string protocols now throw from convertProtocols
- wire-format buffers are checked for zero-length and truncated
  entries
- an empty buffer or array is still accepted and means skip ALPN,
  matching the historical behavior for []

The C++ CHECK_EQ is left unchanged: once JS has validated the input,
a non-zero SSL_set_alpn_protos return is an internal invariant
failure rather than user-facing input.

Fixes: #65069

Signed-off-by: Sankalp Thakur <[email protected]>
PR-URL: #65076
Reviewed-By: Tim Perry <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
@github-actions github-actions Bot mentioned this pull request Aug 25, 2026
2026-08-26, Version 26.8.0 (Current) #65551
Merged
aduh95 pushed a commit that referenced this pull request Aug 27, 2026
@sankalpsthakur @aduh95
tls: throw on invalid ALPNProtocols instead of aborting
810b8e2
tls.connect() with malformed ALPNProtocols hit
CHECK_EQ(0, SSL_set_alpn_protos(...)) in the C++ layer and aborted
the process with SIGABRT.

Validate in JS instead, in convertALPNProtocols, so both client and
server fail early with a recoverable ERR_INVALID_ARG_VALUE:

- zero-length string protocols now throw from convertProtocols
- wire-format buffers are checked for zero-length and truncated
  entries
- an empty buffer or array is still accepted and means skip ALPN,
  matching the historical behavior for []

The C++ CHECK_EQ is left unchanged: once JS has validated the input,
a non-zero SSL_set_alpn_protos return is an internal invariant
failure rather than user-facing input.

Fixes: #65069

Signed-off-by: Sankalp Thakur <[email protected]>
PR-URL: #65076
Reviewed-By: Tim Perry <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
@github-actions github-actions Bot mentioned this pull request Sep 7, 2026
2026-09-08, Version 24.21.0 'Krypton' (LTS) #65873
Merged
aduh95 pushed a commit that referenced this pull request Sep 7, 2026
@sankalpsthakur @aduh95
tls: throw on invalid ALPNProtocols instead of aborting
cd136aa
tls.connect() with malformed ALPNProtocols hit
CHECK_EQ(0, SSL_set_alpn_protos(...)) in the C++ layer and aborted
the process with SIGABRT.

Validate in JS instead, in convertALPNProtocols, so both client and
server fail early with a recoverable ERR_INVALID_ARG_VALUE:

- zero-length string protocols now throw from convertProtocols
- wire-format buffers are checked for zero-length and truncated
  entries
- an empty buffer or array is still accepted and means skip ALPN,
  matching the historical behavior for []

The C++ CHECK_EQ is left unchanged: once JS has validated the input,
a non-zero SSL_set_alpn_protos return is an internal invariant
failure rather than user-facing input.

Fixes: #65069

Signed-off-by: Sankalp Thakur <[email protected]>
PR-URL: #65076
Reviewed-By: Tim Perry <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
aduh95 pushed a commit that referenced this pull request Sep 7, 2026
@sankalpsthakur @aduh95
tls: throw on invalid ALPNProtocols instead of aborting
b0ef155
tls.connect() with malformed ALPNProtocols hit
CHECK_EQ(0, SSL_set_alpn_protos(...)) in the C++ layer and aborted
the process with SIGABRT.

Validate in JS instead, in convertALPNProtocols, so both client and
server fail early with a recoverable ERR_INVALID_ARG_VALUE:

- zero-length string protocols now throw from convertProtocols
- wire-format buffers are checked for zero-length and truncated
  entries
- an empty buffer or array is still accepted and means skip ALPN,
  matching the historical behavior for []

The C++ CHECK_EQ is left unchanged: once JS has validated the input,
a non-zero SSL_set_alpn_protos return is an internal invariant
failure rather than user-facing input.

Fixes: #65069

Signed-off-by: Sankalp Thakur <[email protected]>
PR-URL: #65076
Reviewed-By: Tim Perry <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@jasnell jasnell jasnell approved these changes
@pimterry pimterry pimterry approved these changes
@trivikr trivikr trivikr approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. c++ Issues and PRs that require attention from people who are familiar with C++. crypto Issues and PRs related to the crypto subsystem. needs-ci PRs that need a full CI run.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

tls.connect() aborts process on malformed ALPNProtocols instead of throwing an error

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@sankalpsthakur @nodejs-github-bot @trivikr @jasnell @pimterry
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.