Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 006271f

Browse files
author
Charlie Barto
committed
make Uri.is_host_loopback() only return true for localhost and 127.0.0.1 exactly
1 parent 9c65488 commit 006271f

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

‎Release/include/cpprest/base_uri.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,14 @@ class uri
296296
/// A loopback URI is one which refers to a hostname or ip address with meaning only on the local machine.
297297
/// </summary>
298298
/// <remarks>
299-
/// Examples include "localhost", or ip addresses in the loopback range (127.0.0.0/24).
299+
/// Examples include "localhost", or "127.0.0.1". The only URIs for which this method returns true are "127.0.0.1", and "localhost",
300+
/// all other URIs return false
300301
/// </remarks>
301302
/// <returns><c>true</c> if this URI references the local host, <c>false</c> otherwise.</returns>
302303
bool is_host_loopback() const
303304
{
304305
return !is_empty() &&
305-
((host() == _XPLATSTR("localhost")) || (host().size() > 4 && host().substr(0, 4) == _XPLATSTR("127.")));
306+
((host() == _XPLATSTR("localhost")) || (host()== _XPLATSTR("127.0.0.1")));
306307
}
307308

308309
/// <summary>

‎Release/tests/functional/uri/constructor_tests.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ namespace uri_tests
2424
{
2525
SUITE(constructor_tests)
2626
{
27+
TEST(not_really_a_loopback_uri)
28+
{
29+
uri u(uri::encode_uri(U("https://127.evil.com")));
30+
VERIFY_IS_FALSE(u.is_host_loopback());
31+
}
2732
TEST(parsing_constructor_char)
2833
{
2934
uri u(uri::encode_uri(U("net.tcp://steve:@testname.com:81/bleh%?qstring#goo")));

‎Release/tests/functional/uri/diagnostic_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ SUITE(diagnostic_tests)
8282
VERIFY_IS_FALSE(uri(U("http://bleh/?qstring")).is_host_loopback());
8383
VERIFY_IS_FALSE(uri(U("http://+*/?qstring")).is_host_loopback());
8484
VERIFY_IS_TRUE(uri(U("http://127.0.0.1/")).is_host_loopback());
85-
VERIFY_IS_TRUE(uri(U("http://127.155.0.1/")).is_host_loopback());
85+
VERIFY_IS_FALSE(uri(U("http://127.155.0.1/")).is_host_loopback());
8686
VERIFY_IS_FALSE(uri(U("http://128.0.0.1/")).is_host_loopback());
8787
}
8888

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /