Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] filtering non-safe ASCII header characters from user agent, centralizing #706

Merged
merged 1 commit into from
Jul 29, 2024
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
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]", "");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xkcd.com/1171/

} catch (RuntimeException e) {
Logging.error("Unable to get Java version for user agent string: ",e);
}
Expand Down
Loading