Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
T
Titanium-Web-Proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Titanium-Web-Proxy
Commits
0d628c6d
Commit
0d628c6d
authored
May 25, 2018
by
justcoding121
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor local IP check
parent
2d076556
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
31 deletions
+34
-31
Network.cs
Titanium.Web.Proxy/Helpers/Network.cs
+28
-20
TcpConnectionFactory.cs
Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
+4
-8
ProxyServer.cs
Titanium.Web.Proxy/ProxyServer.cs
+2
-3
No files found.
Titanium.Web.Proxy/Helpers/Network.cs
View file @
0d628c6d
...
...
@@ -28,36 +28,44 @@ namespace Titanium.Web.Proxy.Helpers
internal
static
bool
IsLocalIpAddress
(
string
hostName
)
{
bool
isLocalhost
=
false
;
hostName
=
hostName
.
ToLower
()
;
var
localhost
=
Dns
.
GetHostEntry
(
"127.0.0.1"
);
if
(
hostName
==
localhost
.
HostName
)
if
(
hostName
==
"127.0.0.1"
||
hostName
==
"localhost"
)
{
var
hostEntry
=
Dns
.
GetHostEntry
(
hostName
);
isLocalhost
=
hostEntry
.
AddressList
.
Any
(
IPAddress
.
IsLoopback
);
return
true
;
}
if
(!
isLocalhost
)
var
localhostDnsName
=
Dns
.
GetHostName
().
ToLower
();
//if hostname matches current machine DNS name
if
(
hostName
==
localhostDnsName
)
{
localhost
=
Dns
.
GetHostEntry
(
Dns
.
GetHostName
());
return
true
;
}
var
isLocalhost
=
false
;
IPHostEntry
hostEntry
=
null
;
//check if parsable to an IP Address
if
(
IPAddress
.
TryParse
(
hostName
,
out
var
ipAddress
))
{
isLocalhost
=
localhost
.
AddressList
.
Any
(
x
=>
x
.
Equals
(
ipAddress
));
hostEntry
=
Dns
.
GetHostEntry
(
localhostDnsName
);
isLocalhost
=
hostEntry
.
AddressList
.
Any
(
x
=>
x
.
Equals
(
ipAddress
));
}
if
(!
isLocalhost
)
{
try
{
var
hostEntry
=
Dns
.
GetHostEntry
(
hostName
);
isLocalhost
=
localhost
.
AddressList
.
Any
(
x
=>
hostEntry
.
AddressList
.
Any
(
x
.
Equals
));
hostEntry
=
Dns
.
GetHostEntry
(
hostName
);
isLocalhost
=
hostEntry
.
AddressList
.
Any
(
x
=>
hostEntry
.
AddressList
.
Any
(
x
.
Equals
));
}
catch
(
SocketException
)
{
}
}
}
return
isLocalhost
;
}
...
...
Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
View file @
0d628c6d
...
...
@@ -229,16 +229,12 @@ namespace Titanium.Web.Proxy.Network.Tcp
ProxyServer
proxyServer
,
IPEndPoint
upStreamEndPoint
,
ExternalProxy
externalProxy
,
CancellationToken
cancellationToken
)
{
if
(
remoteHostName
==
"localhost"
||
remoteHostName
==
"127.0.0.1"
||
remoteHostName
==
Dns
.
GetHostName
())
{
if
(
server
.
ProxyEndPoints
.
Any
(
x
=>
x
.
Port
==
remotePort
))
//deny connection to proxy end points to avoid infinite connection loop.
if
(
server
.
ProxyEndPoints
.
Any
(
x
=>
x
.
Port
==
remotePort
)
&&
NetworkHelper
.
IsLocalIpAddress
(
remoteHostName
))
{
throw
new
Exception
(
$"A client is making HTTP request to one of the listening ports of this proxy
{
remoteHostName
}
:
{
remotePort
}
"
);
}
}
bool
useUpstreamProxy
=
false
;
...
...
Titanium.Web.Proxy/ProxyServer.cs
View file @
0d628c6d
...
...
@@ -442,7 +442,7 @@ namespace Titanium.Web.Proxy
systemProxySettingsManager
.
SetProxy
(
Equals
(
endPoint
.
IpAddress
,
IPAddress
.
Any
)
|
Equals
(
endPoint
.
IpAddress
,
IPAddress
.
Loopback
)
?
"
127.0.0.1
"
?
"
localhost
"
:
endPoint
.
IpAddress
.
ToString
(),
endPoint
.
Port
,
protocolType
);
...
...
@@ -545,8 +545,7 @@ namespace Titanium.Web.Proxy
var
protocolToRemove
=
ProxyProtocolType
.
None
;
foreach
(
var
proxy
in
proxyInfo
.
Proxies
.
Values
)
{
if
((
proxy
.
HostName
==
"127.0.0.1"
||
proxy
.
HostName
.
EqualsIgnoreCase
(
"localhost"
))
if
(
NetworkHelper
.
IsLocalIpAddress
(
proxy
.
HostName
)
&&
ProxyEndPoints
.
Any
(
x
=>
x
.
Port
==
proxy
.
Port
))
{
protocolToRemove
|=
proxy
.
ProtocolType
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment