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
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
* Fix: Initialize Logback after context refreshes (#1129)
* Ref: Return NoOpTransaction instead of null (#1126)
* Fix: Do not crash when passing null values to @Nullable methods, eg User and Scope
* Enhancement: Send user.ip_address = {{auto}} when sendDefaultPii is true
* Enhancement: Send user.ip_address = {{auto}} when sendDefaultPii is true (#1015)
* Fix: Resolving dashed properties from external configuration
* Feat: Read `uncaught.handler.enabled` property from the external configuration
* Feat: Read `uncaught.handler.enabled` property from the external configuration
* Fix: Consider {{ auto }} as a default ip address (#1015)

# 4.0.0-alpha.2

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.sentry.spring;

import io.sentry.EventProcessor;
import io.sentry.MainEventProcessor;
import io.sentry.IpAddressUtils;
import io.sentry.SentryEvent;
import io.sentry.SentryOptions;
import io.sentry.protocol.User;
Expand Down Expand Up @@ -46,8 +46,7 @@ public SentryEvent process(final @NotNull SentryEvent event, final @Nullable Obj
}
if (options.isSendDefaultPii()) {
final User existingUser = event.getUser();
if (existingUser != null
&& MainEventProcessor.DEFAULT_IP_ADDRESS.equals(existingUser.getIpAddress())) {
if (existingUser != null && IpAddressUtils.isDefault(existingUser.getIpAddress())) {
// unset {{auto}} as it would set the server's ip address as a user ip address
existingUser.setIpAddress(null);
}
Expand Down
4 changes: 4 additions & 0 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ public abstract interface class io/sentry/Integration {
public abstract fun register (Lio/sentry/IHub;Lio/sentry/SentryOptions;)V
}

public final class io/sentry/IpAddressUtils {
public static fun isDefault (Ljava/lang/String;)Z
}

public final class io/sentry/MainEventProcessor : io/sentry/EventProcessor {
public static final field DEFAULT_IP_ADDRESS Ljava/lang/String;
public fun process (Lio/sentry/SentryEvent;Ljava/lang/Object;)Lio/sentry/SentryEvent;
Expand Down
19 changes: 19 additions & 0 deletions sentry/src/main/java/io/sentry/IpAddressUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.sentry;

import java.util.Arrays;
import java.util.List;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

@ApiStatus.Internal
public final class IpAddressUtils {
static final String DEFAULT_IP_ADDRESS = "{{auto}}";
private static final List<String> DEFAULT_IP_ADDRESS_VALID_VALUES =
Arrays.asList(DEFAULT_IP_ADDRESS, "{{ auto }}");

private IpAddressUtils() {}

public static boolean isDefault(final @Nullable String ipAddress) {
return ipAddress != null && DEFAULT_IP_ADDRESS_VALID_VALUES.contains(ipAddress);
}
}
4 changes: 2 additions & 2 deletions sentry/src/main/java/io/sentry/MainEventProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ private void processNonCachedEvent(final @NotNull SentryEvent event) {
if (options.isSendDefaultPii()) {
if (event.getUser() == null) {
final User user = new User();
user.setIpAddress(DEFAULT_IP_ADDRESS);
user.setIpAddress(IpAddressUtils.DEFAULT_IP_ADDRESS);
event.setUser(user);
} else if (event.getUser().getIpAddress() == null) {
event.getUser().setIpAddress(DEFAULT_IP_ADDRESS);
event.getUser().setIpAddress(IpAddressUtils.DEFAULT_IP_ADDRESS);
}
}
}
Expand Down
23 changes: 23 additions & 0 deletions sentry/src/test/java/io/sentry/IpAddressUtilsTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.sentry

import kotlin.test.Test
import kotlin.test.assertFalse
import kotlin.test.assertTrue

class IpAddressUtilsTest {

@Test
fun `{{auto}} is considered a default address`() {
assertTrue(IpAddressUtils.isDefault("{{auto}}"))
}

@Test
fun `{{ auto }} is considered a default address`() {
assertTrue(IpAddressUtils.isDefault("{{ auto }}"))
}

@Test
fun `real ip address is considered not a default address`() {
assertFalse(IpAddressUtils.isDefault("192.168.0.1"))
}
}