Skip to content

Commit 9c7636b

Browse files
authored
Merge pull request #797 from crimsonvspurple/dev
Bind to Only Loopback Address(es) When Making Interactive Request
2 parents 02da379 + 1b90925 commit 9c7636b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/HttpListener.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.slf4j.Logger;
1212
import org.slf4j.LoggerFactory;
1313

14+
import java.net.InetAddress;
1415
import java.net.InetSocketAddress;
1516

1617
@Accessors(fluent = true)
@@ -25,7 +26,13 @@ class HttpListener {
2526

2627
void startListener(int port, HttpHandler httpHandler) {
2728
try {
28-
server = HttpServer.create(new InetSocketAddress(port), 0);
29+
// since we only allow loopback address, we can use InetAddress.getLoopbackAddress() directly
30+
// why? because currently we are creating Socket using InetSocketAddress(port)
31+
// which is using wildcard address, so it will attempt to bind to all available network interfaces
32+
// that includes private IP like 192.168.x.x, 10.x.x.x, etc.
33+
// which in turns, will trigger the firewall prompt
34+
// https://github.com/AzureAD/microsoft-authentication-library-for-java/issues/796
35+
server = HttpServer.create(new InetSocketAddress(InetAddress.getLoopbackAddress(), port), 0);
2936
server.createContext("/", httpHandler);
3037
this.port = server.getAddress().getPort();
3138
server.start();

0 commit comments

Comments
 (0)