Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ requires 'Modern::Perl';
requires 'Moose';
requires 'MooseX::NonMoose';
requires 'Net::Server::SS::PreFork';
requires 'Net::Telnet';
requires 'PDF::API2';
requires 'Perl6::Junction';
requires 'Plack';
Expand Down
24 changes: 24 additions & 0 deletions lib/Libki/SIP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use feature 'say';

use Data::Dumper;
use IO::Socket::INET;
use Net::Telnet;
use POSIX qw(strftime);
use Socket qw(:crlf);

Expand All @@ -29,6 +30,7 @@ sub authenticate_via_sip {
my $timeout = $config->{SIP}->{timeout} || 15;
my $require_sip_auth = $config->{SIP}->{require_sip_auth}
// 1; # Default to requiring authentication if setting doesn't exist
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.

Expand All @@ -54,6 +56,28 @@ sub authenticate_via_sip {
or $log->fatal("ERROR in Socket Creation : $!\n")
&& ( $test_mode && die "ERROR in Socket Creation : $!\n" );
Comment on lines 56 to 57

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.


say "sip_enable_telnet_login: $sip_enable_telnet_login" if $test_mode;
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 = quotemeta($config->{SIP}->{sip_telnet_login_prompt});
say "login, expecting: $sip_telnet_login_prompt" if $test_mode;
$ok = $telnet->login(
Name => $sip_username,
Password => $sip_password,
Prompt => '/' . $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 };
}
}

## Set location to empty string if not set
$config->{SIP}->{location} //= q{};

Expand Down