RDKB-66901 : harden session handling and request parsing - #42
Closed
pavankumar464 wants to merge 1 commit into
Closed
pavankumar464 wants to merge 1 commit into
pavankumar464 wants to merge 1 commit into
Conversation
- 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
Contributor
Author
|
Contributor
There was a problem hiding this comment.
🟡 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_inputon the first call makes the malformed-request guard one-shot. A template that callssession_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
printhere writesunexpected post datadirectly to stdout before_jst_finishemits HTTP headers, producing an invalid CGI response for malformed input. Buffer the diagnostic withechoor 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 butsource/jst_session.cleavessession_identifierset whenutime()fails. This branch clears only the JavaScript variables, sosession_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_startimplementation 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 fromutime()but leavessession_identifiernon-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()insource/jst_session.cfills all 32 token characters fromgetrandom()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
falsefor every evaluation error makesEXPECT_FALSE(evaluateJavaScriptBoolean(...))pass when the JavaScript throws, masking the missingisSecure()API and other runtime failures. Record the evaluation error withADD_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.
| function _jst_session_cookie() | ||
| { | ||
| var $cookie = "Set-Cookie: DUKSID=" + ccsp_session.getId() + "; httponly"; | ||
| if(ccsp_session.isSecure()) |
| { | ||
| EnvVarGuard cookie_guard("HTTP_COOKIE"); | ||
| const std::string session_id = makeValidSessionId('G'); | ||
| const std::string cookie = "OTHERDUKSID=" + session_id; |
| 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)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Reason for change: Webui Wi-Fi page 500 Internal Error
Test Procedure: Test Webui actions
Risks: Low
Priority: P1