fix: sanitize DNS inputs and guard AWG s3/s4#31
Conversation
📝 WalkthroughWalkthroughThree small fixes: a ChangesDNS Input Sanitization
AmneziaWG s3/s4 Emission Removal
Sequence DiagramsequenceDiagram
participant User
participant SettingsPreferenceFragment
participant EditTextPreference
participant ConfigBuilder
User->>SettingsPreferenceFragment: enters DNS text with control chars
SettingsPreferenceFragment->>SettingsPreferenceFragment: sanitizeDnsPreferenceValue(newValue)
SettingsPreferenceFragment->>EditTextPreference: write sanitized text back if changed
SettingsPreferenceFragment->>ConfigBuilder: trigger reload
ConfigBuilder->>ConfigBuilder: sanitizeDnsEntry(dns) per directDNS line
ConfigBuilder-->>SettingsPreferenceFragment: reload complete
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Comment |
Summary
Validation
Greptile Summary
This PR adds two targeted fixes: DNS inputs are sanitized at both the UI layer (
SettingsPreferenceFragment) and the config-generation layer (ConfigBuilder) by stripping ISO control characters, and the AmneziaWG outbound builder stops emittings3/s4UAPI keys that the bundled amneziawg-go v1.0.4 core does not yet understand.dnsReloadListenersanitizes multi-line DNS text line-by-line, persists the clean value viapreference.text = sanitizedValue, callsneedReload(), and returnsfalseto prevent Android from re-persisting the raw string — correct flow.sanitizeDnsEntryinConfigBuilder.ktprovides defence-in-depth for values arriving via import or programmatic paths that bypass the UI listener.buildSingBoxOutboundAmneziaWGBeanfunction now skips the two UAPI assignments with an explanatory comment; the bean continues to store and round-trip the fields so imported profiles lose no data.Confidence Score: 5/5
Safe to merge — both changes are additive guards with no regressions on existing behavior.
The DNS sanitization is applied correctly at two independent layers (UI persistence and config generation), using standard Kotlin stdlib APIs with no off-by-one or bypass risk. The AmneziaWG s3/s4 removal matches the documented limitation of the bundled core library and preserves round-trip fidelity for imported profiles. No existing paths are broken.
No files require special attention.
Important Files Changed
sanitizeDnsPreferenceValue(line-by-line ISO control char strip + trim) and wiresdnsReloadListenerforremoteDns/directDns; correctly persists the sanitized value viapreference.textbefore returningfalseto block Android from re-persisting the raw string.sanitizeDnsEntry(strips ISO control chars + trims) and applies it toremoteDns/directDnssplit entries — a safe, defence-in-depth layer that covers programmatic/import paths not gated by the UI listener.Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[User edits remoteDns / directDns in UI] --> B[dnsReloadListener called] B --> C{newValue is String?} C -- No --> D[delegate to reloadListener\nneedReload + return true] C -- Yes --> E[sanitizeDnsPreferenceValue\nstrip ISO control chars per-line] E --> F{sanitized != raw?} F -- No --> G[needReload\nreturn true\nAndroid persists raw value] F -- Yes --> H{preference is\nEditTextPreference?} H -- Yes --> I[preference.text = sanitizedValue\npersistString called internally] H -- No --> J[no persist\nsilently discards edit] I --> K[needReload\nreturn false\nblock Android raw-persist] J --> K%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%% flowchart TD A[User edits remoteDns / directDns in UI] --> B[dnsReloadListener called] B --> C{newValue is String?} C -- No --> D[delegate to reloadListener\nneedReload + return true] C -- Yes --> E[sanitizeDnsPreferenceValue\nstrip ISO control chars per-line] E --> F{sanitized != raw?} F -- No --> G[needReload\nreturn true\nAndroid persists raw value] F -- Yes --> H{preference is\nEditTextPreference?} H -- Yes --> I[preference.text = sanitizedValue\npersistString called internally] H -- No --> J[no persist\nsilently discards edit] I --> K[needReload\nreturn false\nblock Android raw-persist] J --> KReviews (2): Last reviewed commit: "fix: reject sanitized DNS fallback safel..." | Re-trigger Greptile