Skip to content

Commit d50a163

Browse files
committed
fix: Improve error reporting for WireGuard profile validation and preserve configuration shape for custom maps
1 parent 20db49b commit d50a163

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

app/src/main/java/io/nekohasekai/sagernet/fmt/ConfigBuilder.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,12 @@ private val wireGuardIntegerFields = setOf("listen_port", "workers", "routing_ma
101101
private val wireGuardStringListFields = setOf("network_type", "fallback_network_type")
102102

103103
private fun wireGuardOverrideError(profileId: Long, field: String, category: String): Nothing {
104+
// Unknown keys are user-controlled and may themselves contain credentials or
105+
// other sensitive text. Keep known schema field names actionable, but report
106+
// unknown input only by category so diagnostics cannot echo arbitrary keys.
107+
val diagnosticField = if (category == "unknown") "<unknown>" else field
104108
throw IllegalArgumentException(
105-
"WireGuard profile $profileId has incompatible custom outbound field '$field' ($category)"
109+
"WireGuard profile $profileId has incompatible custom outbound field '$diagnosticField' ($category)"
106110
)
107111
}
108112

app/src/main/java/moe/matsuri/nb4a/SingBoxOptions.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
8585
} else {
8686
map = gsonSingbox.fromJson(((TypeAdapter<SingBoxOption>) delegate).toJson(src), Map.class);
8787
}
88+
// Preserve the pre-endpoint shape for ordinary configurations. Remove
89+
// only the generated empty top-level container before custom maps are
90+
// merged, so a global custom configuration can still add endpoints.
91+
if (src instanceof MyOptions &&
92+
(((MyOptions) src).endpoints == null || ((MyOptions) src).endpoints.isEmpty())) {
93+
map.remove("endpoints");
94+
}
8895
if (src._hack_config_map != null && !src._hack_config_map.isEmpty()) {
8996
Util.INSTANCE.mergeMap(map, src._hack_config_map);
9097
}

0 commit comments

Comments
 (0)