Skip to content

Conversation

@jfmartinezm
Copy link
Contributor

@jfmartinezm jfmartinezm commented Aug 4, 2025

This PR implements telnet login using Net::Telnet for SIP servers that have it enabled.

Description by Korbit AI

What change is being made?

Add Net::Telnet dependency and implement optional Telnet-based login for SIP authentication when configured via SIP.sip_enable_telnet_login, including prompt handling, credentials, and error reporting.

Why are these changes being made?

To support an alternate SIP authentication method via Telnet when explicitly enabled, enabling compatibility with environments that require Telnet-based login. If not enabled, behavior remains unchanged.

Is this description stale? Ask me to generate a new description by commenting /korbit-generate-pr-description

Comment on lines 56 to 57
or $log->fatal("ERROR in Socket Creation : $!\n")
&& ( $test_mode && die "ERROR in Socket Creation : $!\n" );

Choose a reason for hiding this comment

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

The error handling logic in line 56 uses or and && operators, which might not behave as expected due to operator precedence. This could lead to the die statement not being executed when the socket creation fails in non-test mode.

Recommended Solution:
Use parentheses to ensure the correct execution order, or consider restructuring the logic to handle errors more explicitly, possibly using an if statement to check the result of the socket creation and then handling the error accordingly.

Comment on lines 60 to 78
if ($sip_enable_telnet_login) {
$log->debug("Telnet login enabled");
$telnet = new Net::Telnet( Fhopen => $socket );
$sip_username = $config->{SIP}->{username};
$sip_password = $config->{SIP}->{password};
$sip_telnet_login_prompt = $config->{SIP}->{telnet_login_prompt};
$ok = $telnet->login(
Name => $sip_username,
Password => $sip_password,
Prompt => '/' . quotemeta($sip_telnet_login_prompt) . '/',
Errmode => 'return'
);
if ( !$ok ) {
$telnet_error = $telnet->errmsg;
$log->debug("Telnet error: $telnet_error");
say "telnet error: $telnet_error" if $test_mode;
return { success => 0, error => 'SIP_AUTH_FAILURE', user => $user };
}
}

Choose a reason for hiding this comment

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

The code enables Telnet login if sip_enable_telnet_login is set. Telnet is inherently insecure as it transmits data, including passwords, in plaintext, which can be intercepted by malicious actors.

Recommended Solution:
Consider using a more secure protocol such as SSH for remote logins or ensure that Telnet is only used in a secure, controlled environment. Additionally, ensure that sensitive information is encrypted during transmission to safeguard against eavesdropping.

Copy link

@korbit-ai korbit-ai bot left a comment

Choose a reason for hiding this comment

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

Review by Korbit AI

Korbit automatically attempts to detect when you fix issues in new commits.
Category Issue Status
Readability Inconsistent Assignment Alignment ▹ view
Error Handling Missing Telnet Configuration Validation ▹ view
Functionality Missing Telnet Connection Cleanup ▹ view
Files scanned
File Path Reviewed
lib/Libki/SIP.pm

Explore our documentation to understand the languages and file types we support and the files we ignore.

Check out our docs on how you can make Korbit work best for you and your team.

Loving Korbit!? Share us on LinkedIn Reddit and X

Comment on lines 66 to 71
$ok = $telnet->login(
Name => $sip_username,
Password => $sip_password,
Prompt => '/' . quotemeta($sip_telnet_login_prompt) . '/',
Errmode => 'return'
);
Copy link

Choose a reason for hiding this comment

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

Missing Telnet Configuration Validation category Error Handling

Tell me more
What is the issue?

The telnet login attempt doesn't verify if required configuration parameters (username, password, telnet_login_prompt) exist before using them.

Why this matters

Missing configuration parameters could cause the telnet login to fail silently or with unclear error messages, making it difficult to diagnose authentication issues.

Suggested change ∙ Feature Preview

Add validation before attempting telnet login:

if ($sip_enable_telnet_login) {
    unless ($config->{SIP}->{username} && $config->{SIP}->{password} && $config->{SIP}->{telnet_login_prompt}) {
        $log->error("Missing required Telnet configuration parameters");
        return { success => 0, error => 'TELNET_CONFIG_ERROR', user => $user };
    }
    # ... rest of telnet login code ...
}
Provide feedback to improve future suggestions

Nice Catch Incorrect Not in Scope Not in coding standard Other

💬 Looking for more details? Reply to this comment to chat with Korbit.

Comment on lines 60 to 77
if ($sip_enable_telnet_login) {
$log->debug("Telnet login enabled");
$telnet = new Net::Telnet( Fhopen => $socket );
$sip_username = $config->{SIP}->{username};
$sip_password = $config->{SIP}->{password};
$sip_telnet_login_prompt = $config->{SIP}->{telnet_login_prompt};
$ok = $telnet->login(
Name => $sip_username,
Password => $sip_password,
Prompt => '/' . quotemeta($sip_telnet_login_prompt) . '/',
Errmode => 'return'
);
if ( !$ok ) {
$telnet_error = $telnet->errmsg;
$log->debug("Telnet error: $telnet_error");
say "telnet error: $telnet_error" if $test_mode;
return { success => 0, error => 'SIP_AUTH_FAILURE', user => $user };
}
Copy link

Choose a reason for hiding this comment

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

Missing Telnet Connection Cleanup category Functionality

Tell me more
What is the issue?

The code doesn't properly handle closing the telnet connection after use, which could lead to resource leaks.

Why this matters

Unclosed telnet connections can accumulate over time, potentially exhausting system resources and causing connection failures.

Suggested change ∙ Feature Preview

Add proper connection cleanup:

my $telnet;
if ($sip_enable_telnet_login) {
    $telnet = new Net::Telnet( Fhopen => $socket );
    # ... rest of telnet code ...
}
# Add at end of authenticate_via_sip function, before the final return:
$telnet->close() if $telnet;
Provide feedback to improve future suggestions

Nice Catch Incorrect Not in Scope Not in coding standard Other

💬 Looking for more details? Reply to this comment to chat with Korbit.

my $sip_enable_telnet_login = $config->{SIP}->{sip_enable_telnet_login};

$log->debug("SIP SERVER: $host:$port");
say "SIP SERVER: $host:$port" if $test_mode;

Choose a reason for hiding this comment

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

Using say for outputting sensitive information such as SIP server addresses in a production environment can lead to security risks if the output is accessible in shared logs or consoles. This practice should be avoided or secured to ensure that sensitive information is not exposed.

Recommended Solution:
Consider using controlled logging mechanisms with appropriate access restrictions instead of using say for debugging outputs.

@sekjal sekjal merged commit 42e60bd into Libki:master Oct 28, 2025
5 checks passed
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