Skip to content

RDKB-66901 : harden session handling and request parsing - #42

Closed
pavankumar464 wants to merge 1 commit into
developfrom
bug/RDKB-66901
Closed

pavankumar464 wants to merge 1 commit into
developfrom
bug/RDKB-66901

Conversation

@pavankumar464

Copy link
Copy Markdown
Contributor

Reason for change: Webui Wi-Fi page 500 Internal Error
Test Procedure: Test Webui actions
Risks: Low
Priority: P1

- revalidate active sessions and prevent stale proxy persistence

- handle failed session creation and startup safely

- expire DUKSID on logout and preserve secure-cookie behavior

- parse standalone DUKSID cookie fields only

- retain equals signs in GET, POST, and file metadata values

- add prefix-runtime regression tests and synchronize parser fixtures
Copilot AI lite review requested due to automatic review settings September 16, 2026 04:18
@pavankumar464
pavankumar464 requested a review from a team as a code owner September 16, 2026 04:18
@pavankumar464

Copy link
Copy Markdown
Contributor Author
  • revalidate active sessions and prevent stale proxy persistence
  • handle failed session creation and startup safely
  • expire DUKSID on logout and preserve secure-cookie behavior
  • parse standalone DUKSID cookie fields only
  • retain equals signs in GET, POST, and file metadata values
  • add prefix-runtime regression tests and synchronize parser fixtures

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved critical and moderate findings affect session runtime behavior, cookie parsing, stale-session cleanup, and test correctness.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Hardens JST session handling and request parsing to address WebUI Wi-Fi page failures.

Changes:

  • Adds session lifecycle and secure-cookie handling.
  • Preserves = characters in request values.
  • Expands regression tests and regenerates parser fixtures.
File summaries
File Description
tests/parser/jst_prefix.js Updated parser prefix fixture.
tests/parser/jst_parser_template_block_string.jst.parsed Regenerated parser output.
tests/parser/jst_parser_template_block_content.jst.parsed Regenerated parser output.
tests/parser/jst_parser_skip_whitespace.jst.parsed Regenerated parser output.
tests/parser/jst_parser_single_quotes.jst.parsed Regenerated parser output.
tests/parser/jst_parser_line_feeds.jst.parsed Regenerated parser output.
tests/parser/jst_parser_include_unknown.jst.parsed Regenerated parser output.
tests/parser/jst_parser_include_runtime.jst.parsed Regenerated parser output.
tests/parser/jst_parser_include_once.jst.parsed Regenerated parser output.
tests/parser/jst_parser_include_not_if_in_line_comment.jst.parsed Regenerated parser output.
tests/parser/jst_parser_include_not_if_in_content.jst.parsed Regenerated parser output.
tests/parser/jst_parser_include_not_if_in_block_comment.jst.parsed Regenerated parser output.
tests/parser/jst_parser_include_nested.jst.parsed Regenerated parser output.
tests/parser/jst_parser_include_malformed_1.jst.parsed Regenerated parser output.
tests/parser/jst_parser_include_code_before.jst.parsed Regenerated parser output.
tests/parser/jst_parser_include_code_after.jst.parsed Regenerated parser output.
tests/parser/jst_parser_comment_tag.jst.parsed Regenerated parser output.
tests/parser/jst_parser_backslash.jst.parsed Regenerated parser output.
tests/parser_test.cpp Adds session and parsing regression tests.
jsts/jst_prefix.js Updates runtime session and request handling.
Review details

Suppressed comments (7)

jsts/jst_prefix.js:120

  • Resetting _val_input on the first call makes the malformed-request guard one-shot. A template that calls session_start() again after the first false result can then create a session from the same invalid request; keep the failure state for the rest of the request.
  if($_val_input == 1)
  {
    $_val_input = 0;
    return false;

jsts/jst_prefix.js:241

  • Calling print here writes unexpected post data directly to stdout before _jst_finish emits HTTP headers, producing an invalid CGI response for malformed input. Buffer the diagnostic with echo or route it through the normal error-response path instead.
    {
      print("unexpected post data");
      $_val_input = 1;

jsts/jst_prefix.js:115

  • When an already-started session becomes stale, the native start() returns false but source/jst_session.c leaves session_identifier set when utime() fails. This branch clears only the JavaScript variables, so session_status() remains true and the stale native ID can be reused. Clear the native session state as well, preferably in the native failure path before returning false.
    if(ccsp_session.start())
      return true;

    $_jst_session = null;
    $_SESSION = {};
    return false;

tests/parser_test.cpp:661

  • The native session_start implementation does not inspect HTTPS/REQUEST_SCHEME or otherwise bind a session ID to a request scheme, so a valid file-backed cookie is accepted when the request changes scheme. This expectation cannot pass until scheme binding is implemented in the native session layer.
  EXPECT_FALSE(duk_get_boolean(ctx, -1));

tests/parser_test.cpp:747

  • After the session file is removed, native session_start() returns false from utime() but leaves session_identifier non-NULL; getStatus() then still returns true. The final assertion in this test fails and the prefix can report an inactive session as active. Clear the native identifier/status on stale-file failure.
  duk_get_prop_string(ctx, -1, "getStatus");
  ASSERT_EQ(duk_pcall(ctx, 0), DUK_EXEC_SUCCESS);
  EXPECT_FALSE(duk_get_boolean(ctx, -1));

tests/parser_test.cpp:887

  • session_create() in source/jst_session.c fills all 32 token characters from getrandom() and never forces the first token character to encode the request scheme. charAt(8) === '1' is therefore nondeterministic and usually false, even if secure detection is added. Make scheme encoding part of native ID generation or assert only the cookie attribute.
  EXPECT_TRUE(evaluateJavaScriptBoolean(ctx, "session_id().charAt(8) === '1'"));

tests/parser_test.cpp:234

  • Returning false for every evaluation error makes EXPECT_FALSE(evaluateJavaScriptBoolean(...)) pass when the JavaScript throws, masking the missing isSecure() API and other runtime failures. Record the evaluation error with ADD_FAILURE() (or return a separate success status) before returning the boolean result.
  if (duk_peval_string(ctx, source) != DUK_EXEC_SUCCESS)
  {
    duk_pop(ctx);
    return false;
  }
  • Files reviewed: 20/20 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread jsts/jst_prefix.js
function _jst_session_cookie()
{
var $cookie = "Set-Cookie: DUKSID=" + ccsp_session.getId() + "; httponly";
if(ccsp_session.isSecure())
Comment thread tests/parser_test.cpp
{
EnvVarGuard cookie_guard("HTTP_COOKIE");
const std::string session_id = makeValidSessionId('G');
const std::string cookie = "OTHERDUKSID=" + session_id;
Comment thread tests/parser_test.cpp
duk_get_global_string(ctx, "ccsp_session");
duk_get_prop_string(ctx, -1, "getData");
ASSERT_EQ(duk_pcall(ctx, 0), DUK_EXEC_SUCCESS);
EXPECT_TRUE(duk_is_object(ctx, -1));
@pavankumar464
pavankumar464 deleted the bug/RDKB-66901 branch September 16, 2026 04:36
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants