[audit][plugin-api] TSSslClientContextsNamesGet returns pointers into config-owned strings that dangle after SSL config reload

Open
#35 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
52/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
cpp
Domain
api, security

Research direction

Start in src/api/InkAPI.cc around TSSslClientContextsNamesGet at lines 8146-8166, then inspect its declaration and the TSSslSecretGet contract in ts.h. Verify the returned names' lifetime across SSL configuration reloads; done means the API no longer exposes dangling pointers and its ownership or lifetime contract is explicit and tested.

Written by the indexing model from the issue text.

Description

area:plugin-api audit severity:medium

Severity: medium · Category: use-after-free
Location: src/api/InkAPI.cc:8159

What's wrong

The function fills the caller's result array with string_view::data() pointers taken from the keys of params->top_level_ctx_map, then immediately calls SSLConfig::release(params) and returns. The function keeps no reference on behalf of the caller: as soon as an ssl_multicert/records reload retires that SSLConfigParams generation and the last other reference drops, the std::string keys backing every returned const char* are destroyed, and the plugin holds dangling pointers. The API's documented usage pattern ('call TSSslClientContextsNamesGet first to determine which lookup keys are present before querying') encourages holding these pointers across calls, exactly the window in which a reload frees them. Nothing in ts.h or the function copies the names or warns about the lifetime.

Evidence
InkAPI.cc:8146-8166:
    auto  mem = static_cast<std::string_view *>(alloca(sizeof(std::string_view) * n));
    ...
    for (int i = 0; i < idx; i++) {
      result[i] = mem[i].data();
    }
  }
  ...
  SSLConfig::release(params);
  return TS_SUCCESS;
Suggested fix

Copy the names into TSmalloc'd storage the caller frees (matching TSSslSecretGet's contract), or document that the pointers are only valid until the next SSL configuration reload and provide a lifetime-safe variant.


Filed from an automated multi-lens codebase audit. Full report: CODEBASE_AUDIT.md / audit-report.html on branch claude/codebase-audit-review-9nw7vz.

Dominant language
C++
Stars
0
Forks
0
Avg merge
8h 2m
Merged PRs (30d)
21

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from JakeChampion/trafficserver

All issues in JakeChampion/trafficserver

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.