Skip to content

Commit 0f7d6c7

Browse files
committed
Ip Filter allow local host to properties
1 parent a9ecc5b commit 0f7d6c7

3 files changed

Lines changed: 9 additions & 6 deletions

File tree

src/main/kotlin/io/openfuture/api/config/filter/ApiAuthorizationFilter.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ class ApiAuthorizationFilter(
1717

1818
private val ipV4LoopBack = "127.0.0.1"
1919
private val ipV6LoopBack = "0:0:0:0:0:0:0:1"
20-
var allowLocalhost = true
2120

2221
override fun init(filterConfig: FilterConfig?) {
2322
// Do nothing
@@ -44,14 +43,16 @@ class ApiAuthorizationFilter(
4443
fun isAllowed(request: HttpServletRequest): Boolean {
4544

4645
val ip = request.remoteAddr
47-
if (allowLocalhost && (ipV4LoopBack == ip || ipV6LoopBack == ip)) {
46+
if (properties.allowLocalHost && (ipV4LoopBack == ip || ipV6LoopBack == ip)) {
4847
return true
4948
}
5049

51-
val matcher = IpAddressMatcher(properties.cidr)
50+
if (properties.cidr != null) {
51+
val matcher = IpAddressMatcher(properties.cidr)
5252

53-
if (matcher.matches(request.getHeader("X-Forwarded-For"))) {
54-
return true
53+
if (matcher.matches(request.getHeader("X-Forwarded-For"))) {
54+
return true
55+
}
5556
}
5657

5758
return false

src/main/kotlin/io/openfuture/api/config/propety/AuthorizationProperties.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ import javax.validation.constraints.NotEmpty
1111
class AuthorizationProperties(
1212
@field:NotEmpty var cookieName: String? = null,
1313
var expireApi: Long? = 10,
14-
var cidr: String? = null
14+
var cidr: String? = null,
15+
var allowLocalHost: Boolean = false
1516
)

src/main/resources/application.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ ethereum.event-subscription=${EVENT_SUBSCRIPTION}
2121
auth.cookie-name=open_key
2222
auth.expire-api=10
2323
auth.cidr=${PUBLIC_IP_SUBNET}
24+
auth.allow-local-host=false
2425

2526
# WIDGET
2627
widget.host=${WIDGET_HOST}

0 commit comments

Comments
 (0)