Skip to content

Commit

Permalink
filtering non-safe ASCII header characters from user agent, centraliz…
Browse files Browse the repository at this point in the history
…ing (#706)

Co-authored-by: Andy Carra <rksh@wigle.net>
  • Loading branch information
rksh and Andy Carra authored Jul 29, 2024
1 parent 6735fdc commit 4a7d82f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.wigle.wigleandroid.db.DatabaseHelper;
import net.wigle.wigleandroid.TokenAccess;
import net.wigle.wigleandroid.WiGLEAuthException;
import net.wigle.wigleandroid.net.WiGLEApiManager;
import net.wigle.wigleandroid.util.FileAccess;
import net.wigle.wigleandroid.util.FileUtility;
import net.wigle.wigleandroid.util.Logging;
Expand Down Expand Up @@ -93,27 +94,12 @@ public static HttpURLConnection connect(String urlString, final boolean setBound
return createConnection(connectURL, setBoundary, preConnectConfigurator, connectionMethod);
}

public static String getUserAgentString() {
String javaVersion = "unknown";
try {
javaVersion = System.getProperty("java.vendor") + " " +
System.getProperty("java.version") + ", jvm: " +
System.getProperty("java.vm.vendor") + " " +
System.getProperty("java.vm.name") + " " +
System.getProperty("java.vm.version") + " on " +
System.getProperty("os.name") + " " +
System.getProperty("os.version") +
" [" + System.getProperty("os.arch") + "]";
} catch (RuntimeException ignored) { }
return "WigleWifi ("+javaVersion+")";
}

private static HttpURLConnection createConnection(final URL connectURL, final boolean setBoundary,
final PreConnectConfigurator preConnectConfigurator,
final String connectionMethod)
throws IOException {

final String userAgent = AbstractApiRequest.getUserAgentString();
final String userAgent = WiGLEApiManager.USER_AGENT;

// Open a HTTP connection to the URL
HttpURLConnection conn = (HttpURLConnection) connectURL.openConnection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public class WiGLEApiManager {
System.getProperty("os.name") + " " +
System.getProperty("os.version") +
" [" + System.getProperty("os.arch") + "]";
javaVersion = javaVersion.replaceAll("[^\\x00-\\x7F]", "");
} catch (RuntimeException e) {
Logging.error("Unable to get Java version for user agent string: ",e);
}
Expand Down

0 comments on commit 4a7d82f

Please sign in to comment.