Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 17, 2026

Cookie Persistence Implementation - Context-Aware Storage ✅

Merge Conflict Resolution

Resolved conflicts between cookie persistence branch and main branch's playlist handling features:

Files Merged:

  • Plugins/SiriusXM/Bin/sxm.pl - Added both cookiefile and segment_drop to %CONFIG
  • Plugins/SiriusXM/Plugin.pm - Added both preferences with proper initialization
  • Plugins/SiriusXM/Proxy.pm - Pass both cookiefile and segment-drop to sxm.pl
  • Plugins/SiriusXM/Settings.pm - Handle both preferences for restart detection
  • Plugins/SiriusXM/HTML/EN/plugins/SiriusXM/settings/basic.html - Added segment_drop UI field
  • Plugins/SiriusXM/strings.txt - Added segment_drop description strings

Features Implemented

Context-Aware Cookie Persistence:

  • Global cookies (long-lived authentication: SXMDATA, SXMAKTOKEN) stored in siriusxm-cookies.txt
  • Channel-specific cookies (includes JSESSIONID, AWSALB, and long-lived cookies) stored in unique files: siriusxm-cookies-channel-{channel_id}.txt
  • Both cookie types persist to disk with autosave => 1 and ignore_discard => 1
  • Cookie files are properly deleted when clearing cookies and recreated fresh
  • Proactive cookie renewal before expiration (1-hour threshold)
  • Cookiefile path configured in Plugin.pm and passed to sxm.pl
  • Fallback to system temp directory when not set

JSESSIONID Lifetime Management:

  • Added SESSION_MAX_LIFE constant (14400s = 4 hours) for JSESSIONID lifetime estimation
  • JSESSIONID typically has no expiration in the cookie - estimated lifetime is logged
  • Enhanced cookie analysis logs all authentication cookies (SXMDATA, SXMAKTOKEN, JSESSIONID, AWSALB)
  • Expiration detection works for cookies with or without explicit expiry timestamps

Cookie Context Management:

  • All cookie operations maintain proper context (global vs channel-specific)
  • get_channel_cookie_jar() creates persistent jars with unique filenames per channel
  • clear_channel_cookies() deletes disk files and creates fresh jars
  • analyze_cookies() provides context-aware logging with human-readable expiration times

Playlist Handling (merged from main):

  • Segment pre-caching for HLS playlist streaming
  • Configurable segment drop (0-30 segments)
  • HLS compliance and performance optimizations

All features work together without conflicts.

Original prompt

Objective: Enhance the SiriusXM proxy server (sxm.pl) to persist authentication cookies to disk across restarts and add command-line configurability for the cookie storage path. This will improve user experience by avoiding the need for frequent reauthentication, enable reuse of long-lived authentication cookies, and ensure flexibility for different operating environments.

Key Changes:

  1. Persist Cookies to Disk:

    • Use the HTTP::Cookies module's file storage capabilities to automatically save and reload cookies.
    • Introduce logic to persist authentication cookies between proxy restarts. Ensure safe handling to prevent overwriting or corruption of the cookie file.
  2. Command-line Option for Cookie Storage Path:

    • Add a new command-line option --cookiefile to specify an arbitrary path for the cookie storage file.
    • Use the $cache_dir approach as a fallback for determining the default storage location if --cookiefile is not provided:
      $cache_dir = Slim::Utils::OSDetect::dirsFor('cache');
      Combine $cache_dir with a filename (e.g., siriusxm-cookies.txt) to set the default path.
  3. Analyze and Log Cookie Aging:

    • For the authentication cookies (e.g., SXMDATA, SXMAKTOKEN), log the expiration time in human-readable format at startup and whenever they are loaded.
    • Add debugging in existing functions (e.g., is_logged_in) to analyze remaining lifespan of cookies and handle session validation gracefully.
  4. Graceful Reauthentication:

    • Modify the is_logged_in and login functions to detect expired or revoked cookies and prompt reauthentication as needed.

Implementation Details:

  • Update the global configuration (%CONFIG) to include a cookiefile option.
  • Integrate the HTTP::Cookies persistence methods (e.g., new, save, load) into the overall authentication flow.
  • Add documentation and usage examples for the new --cookiefile option.

Steps:

  1. Extend %CONFIG to include cookiefile with a default value derived from $cache_dir.
  2. Update init_logging and similar initialization functions to create the cache directory if not already present.
  3. Modify the HTTP::Cookies instantiation in SiriusXM to use the cookiefile path.
  4. Add meaningful logging around loading and saving cookies, analyzing their expiration, and detecting invalid states.
  5. Update the CLI help text to describe the new option.
  6. Test both the default behavior (using $cache_dir) and user-specified paths for cookie storage.

This pull request was created from Copilot chat.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits January 17, 2026 00:50
- Add --cookiefile command-line option to specify cookie storage path
- Use cache_dir as fallback for default storage location
- Implement HTTP::Cookies file persistence with autosave
- Add analyze_cookies method to log cookie expiration information
- Update is_logged_in and is_session_authenticated to detect expired cookies
- Log cookie information after successful login and authentication
- Create cache directory if not present during init_logging
- Update CLI help text with new cookiefile option

Co-authored-by: paul-1 <6473457+paul-1@users.noreply.github.com>
Co-authored-by: paul-1 <6473457+paul-1@users.noreply.github.com>
- Add comments explaining why warn is used before logging initialization
- Add comment clarifying return value purpose in analyze_cookies
- Note that POSIX import in SiriusXM package is necessary (separate namespace)

Co-authored-by: paul-1 <6473457+paul-1@users.noreply.github.com>
Copilot AI changed the title [WIP] Enhance SiriusXM proxy to persist authentication cookies Add persistent cookie storage to SiriusXM proxy server Jan 17, 2026
Copilot AI requested a review from paul-1 January 17, 2026 00:58
Copy link
Owner

@paul-1 paul-1 left a comment

Choose a reason for hiding this comment

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

@copilot please make changes to the complete plugin, as noted.

Also, when analyzing the cookies, once we know when a cookie will expire, we should make sure to renew the cookie a little before it actually expires.

Comment on lines 186 to 217
# Set up cache directory and default cookie file if not specified
if (!defined $CONFIG{cookiefile}) {
my $cache_dir = Slim::Utils::OSDetect::dirsFor('cache');

# Create cache directory if it doesn't exist
if (!-d $cache_dir) {
eval {
make_path($cache_dir, { mode => 0755 });
};
if ($@) {
# Use warn here since logging system is not yet initialized
warn "Warning: Could not create cache directory $cache_dir: $@\n";
}
}

$CONFIG{cookiefile} = File::Spec->catfile($cache_dir, 'siriusxm-cookies.txt');
}

# Ensure directory for cookiefile exists
if ($CONFIG{cookiefile}) {
my $cookie_dir = dirname($CONFIG{cookiefile});
if (!-d $cookie_dir) {
eval {
make_path($cookie_dir, { mode => 0755 });
};
if ($@) {
# Use warn here since logging system is not yet initialized
warn "Warning: Could not create cookie directory $cookie_dir: $@\n";
}
}
}

Copy link
Owner

Choose a reason for hiding this comment

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

This is wrong. my $cache_dir = Slim::Utils::OSDetect::dirsFor('cache'); should be a modification of Plugin.pm, and passed to sxm.pl as a command line option when starting the proxy in Proxy.pm

If this is not set on command line, it should use the system temp dir.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in d350ab9. The cache_dir logic is now in Plugin.pm where it sets the cookiefile preference, and Proxy.pm passes it to sxm.pl via --cookiefile parameter. sxm.pl uses system temp dir ($ENV{TMPDIR} or /tmp) as fallback when not set on command line.

- Move cache_dir logic from sxm.pl to Plugin.pm
- Add cookiefile preference in Plugin.pm initialization
- Pass cookiefile as command-line parameter via Proxy.pm
- Use system temp dir as fallback in sxm.pl when not set
- Add proactive cookie renewal before expiration
- Implement should_renew_cookies() method with 1-hour threshold
- Update is_logged_in() to trigger renewal before cookies expire

Co-authored-by: paul-1 <6473457+paul-1@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 17, 2026

@copilot please make changes to the complete plugin, as noted.

Also, when analyzing the cookies, once we know when a cookie will expire, we should make sure to renew the cookie a little before it act...

Completed in d350ab9. Changes made to the complete plugin:

  • Plugin.pm: Sets cookiefile preference using cache directory
  • Proxy.pm: Passes cookiefile to sxm.pl as command-line parameter
  • sxm.pl: Implements proactive cookie renewal with should_renew_cookies() method

Cookies are now automatically renewed before expiration (1-hour threshold). When a cookie expires within 1 hour, is_logged_in() returns false to trigger reauthentication and renew the cookie.

Copilot AI requested a review from paul-1 January 17, 2026 03:22
@paul-1
Copy link
Owner

paul-1 commented Jan 17, 2026

@copilot please rebase your changes.

Copy link
Contributor Author

Copilot AI commented Jan 17, 2026

@copilot please rebase your changes.

I see the branch has 5 commits. Would you like me to:

  1. Squash all commits into a single commit with a comprehensive message?
  2. Remove the empty "Initial plan" commit and keep the others?
  3. Rebase onto a specific base branch (which branch)?

Since I cannot execute git rebase directly, could you clarify what you'd like me to do, or would you prefer to handle the rebase manually?

@paul-1
Copy link
Owner

paul-1 commented Jan 17, 2026

@copilot @copilot, can you fix the merge conflicts in this branch

- Merged cookiefile and segment_drop configuration options in %CONFIG
- Added segment_drop preference initialization in Plugin.pm
- Updated Proxy.pm to pass segment_drop parameter to sxm.pl
- Added segment-drop command-line option parsing in sxm.pl
- Updated Settings.pm to handle segment_drop preference changes
- Added segment_drop UI field in basic.html settings page
- Added PLUGIN_SIRIUSXM_SEGMENT_DROP strings
- Resolved merge conflicts with origin/main playlist caching features

Co-authored-by: paul-1 <6473457+paul-1@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 17, 2026

@copilot @copilot, can you fix the merge conflicts in this branch

Fixed in 06fe84a. Resolved merge conflicts with origin/main by integrating both the cookie persistence features and the new playlist handling/segment caching features. The conflicts were in:

  • Plugins/SiriusXM/Bin/sxm.pl: Merged cookiefile and segment_drop config
  • Plugins/SiriusXM/Plugin.pm: Added both preferences
  • Plugins/SiriusXM/Proxy.pm: Pass both parameters to sxm.pl
  • Plugins/SiriusXM/Settings.pm: Handle both in restart detection
  • Plugins/SiriusXM/HTML/EN/plugins/SiriusXM/settings/basic.html: Added segment_drop UI
  • Plugins/SiriusXM/strings.txt: Added segment_drop strings

Both feature sets now work together.

# Conflicts:
#	Plugins/SiriusXM/Bin/sxm.pl
#	Plugins/SiriusXM/Plugin.pm
Copy link
Owner

@paul-1 paul-1 left a comment

Choose a reason for hiding this comment

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

@copilot we have 2 types of cookies.

global, which is along lived cookie
channel specific, which also contain the long lived cookies, but also the shorter lived JSESSIONID. Lets make sure that all cookies are being saved, using unique name
based on the context.

Verify all cookie usage and cookie functions are using the correct context. When specifically clearing a cookie, we need to make sure that it clears the disk file as well and gets properly recreated.

- Add SESSION_MAX_LIFE constant (14400s/4 hours) for JSESSIONID lifetime estimation
- Update get_channel_cookie_jar to create persistent cookie jars for each channel with unique filenames
- Update clear_channel_cookies to delete disk files when clearing cookies
- Enhance analyze_cookies to handle JSESSIONID without expiry and estimate lifetime
- Add AWSALB and JSESSIONID to cookie analysis logging
- Channel-specific cookies now persist to disk as siriusxm-cookies-channel-{id}.txt
- Global cookies continue to use siriusxm-cookies.txt
- Cookie file deletion on clear ensures proper recreation

Co-authored-by: paul-1 <6473457+paul-1@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 17, 2026

@copilot we have 2 types of cookies.

global, which is along lived cookie...

Fixed in 0550de2. Changes implemented:

  1. Cookie persistence with unique filenames:

    • Global cookies: siriusxm-cookies.txt
    • Channel-specific: siriusxm-cookies-channel-{id}.txt
  2. Updated get_channel_cookie_jar(): Creates persistent HTTP::Cookies jars with autosave for each channel

  3. Updated clear_channel_cookies(): Deletes disk files when clearing (using unlink), then recreates fresh jars

  4. Enhanced analyze_cookies(): Now logs all authentication cookies (SXMDATA, SXMAKTOKEN, JSESSIONID, AWSALB) with proper context

  5. Verified cookie usage: All functions use get_channel_cookie_jar() and set_channel_context() correctly throughout the codebase

Copilot AI changed the title Add persistent cookie storage to SiriusXM proxy server Add persistent cookie storage with context-aware management to SiriusXM proxy server Jan 17, 2026
Copilot AI requested a review from paul-1 January 17, 2026 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants