Title: [225562] trunk
Revision
225562
Author
[email protected]
Date
2017-12-05 17:59:53 -0800 (Tue, 05 Dec 2017)

Log Message

Limit user agent versioning to an upper bound
https://bugs.webkit.org/show_bug.cgi?id=180365
<rdar://problem/34550617>

Reviewed by Joseph Pecoraro.

Source/WebCore:

Freeze the version reported as User Agent to OS 10.13.4 (OS 11.3 on iOS) and WebKit 605.1.15
for User Agent purposes.

Test: fast/dom/navigator-userAgent-frozen.html

* page/cocoa/UserAgent.h:
* page/cocoa/UserAgent.mm:
(WebCore::versionPredatesFreeze): Helper function. Returns true for Version 10.13.3 or older.
(WebCore::systemMarketingVersionForUserAgentString):
(WebCore::userAgentBundleVersion):
(WebCore::userVisibleWebKitBundleVersionFromFullVersion): Deleted.
(WebCore::userAgentBundleVersionFromFullVersionString): Deleted.
* page/ios/UserAgentIOS.mm:
(WebCore::standardUserAgentWithApplicationName): Don't take the WebKit bundle version
as an argument, or pass it to the user agent string generator.
* page/mac/UserAgentMac.mm:
(WebCore::standardUserAgentWithApplicationName): Ditto.

Source/WebKit:

* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::standardUserAgent): Don't pass the WebKit bundle version when
creatin the User Agent string.
(WebKit::webKitBundleVersionString): Deleted.
* UIProcess/mac/WebPageProxyMac.mm:
(WebKit::WebPageProxy::standardUserAgent): Ditto.
(WebKit::webKitBundleVersionString): Deleted.

Source/WebKitLegacy/mac:

* WebView/WebView.mm:
(+[WebView _standardUserAgentWithApplicationName:]): Don't pass the WebKit bundle version when
creating the User Agent string.
(webKitBundleVersionString): Deleted.

LayoutTests:

* fast/dom/navigator-userAgent-frozen-expected.txt: Added.
* fast/dom/navigator-userAgent-frozen.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (225561 => 225562)


--- trunk/LayoutTests/ChangeLog	2017-12-06 01:47:29 UTC (rev 225561)
+++ trunk/LayoutTests/ChangeLog	2017-12-06 01:59:53 UTC (rev 225562)
@@ -1,3 +1,14 @@
+2017-12-05  Brent Fulgham  <[email protected]>
+
+        Limit user agent versioning to an upper bound
+        https://bugs.webkit.org/show_bug.cgi?id=180365
+        <rdar://problem/34550617>
+
+        Reviewed by Joseph Pecoraro.
+
+        * fast/dom/navigator-userAgent-frozen-expected.txt: Added.
+        * fast/dom/navigator-userAgent-frozen.html: Added.
+
 2017-12-05  Javier Fernandez  <[email protected]>
 
         [css-grid] Update imported Web Platform Tests

Added: trunk/LayoutTests/fast/dom/navigator-userAgent-frozen-expected.txt (0 => 225562)


--- trunk/LayoutTests/fast/dom/navigator-userAgent-frozen-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/navigator-userAgent-frozen-expected.txt	2017-12-06 01:59:53 UTC (rev 225562)
@@ -0,0 +1,12 @@
+Confirm WebKit does not report versions above the frozen maximums.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS Major version number is within bounds.
+PASS Minor version number is within bounds.
+PASS Tiny version number is within bounds.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/dom/navigator-userAgent-frozen.html (0 => 225562)


--- trunk/LayoutTests/fast/dom/navigator-userAgent-frozen.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/navigator-userAgent-frozen.html	2017-12-06 01:59:53 UTC (rev 225562)
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script>
+description("Confirm WebKit does not report versions above the frozen maximums.");
+</script>
+</head>
+<body>
+<script>
+function testVersion(userAgent)
+{
+    var start = userAgent.indexOf("AppleWebKit/");
+    if (start < 0) {
+        testFailed("User agent did not contain WebKit version.");
+        return;
+    }
+
+    start += 12;
+
+    var end = userAgent.indexOf(" ", start);
+    if (end < 0) {
+        testFailed("Couldn't find end of the version string.");
+        return;
+    }
+
+    var version = userAgent.substr(start, end - start);
+    if (version == "") {
+        testFailed("Malformed version string.");
+        return;
+    }
+    
+    var versionComponents = version.split('.');
+    if (versionComponents[0] <= 605)
+        testPassed("Major version number is within bounds.");
+    else
+        testFailed("Major version number is " + versionComponents[0]);
+
+    if (versionComponents.length < 2)
+        return;
+
+    if (versionComponents[0] < 605 || versionComponents[1] <= 1)
+        testPassed("Minor version number is within bounds.");
+    else
+        testFailed("Minor version number is " + versionComponents[1]);
+
+    if (versionComponents.length < 3)
+        return;
+
+    if (versionComponents[0] < 605 || versionComponents[1] < 1 || versionComponents[2] <= 15)
+        testPassed("Tiny version number is within bounds.");
+    else
+        testFailed("Tiny version number is " + versionComponents[2]);
+}
+
+if (window.testRunner)
+    testRunner.dumpAsText();
+
+testVersion(navigator.userAgent);
+</script>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (225561 => 225562)


--- trunk/Source/WebCore/ChangeLog	2017-12-06 01:47:29 UTC (rev 225561)
+++ trunk/Source/WebCore/ChangeLog	2017-12-06 01:59:53 UTC (rev 225562)
@@ -1,3 +1,29 @@
+2017-12-05  Brent Fulgham  <[email protected]>
+
+        Limit user agent versioning to an upper bound
+        https://bugs.webkit.org/show_bug.cgi?id=180365
+        <rdar://problem/34550617>
+
+        Reviewed by Joseph Pecoraro.
+
+        Freeze the version reported as User Agent to OS 10.13.4 (OS 11.3 on iOS) and WebKit 605.1.15
+        for User Agent purposes.
+
+        Test: fast/dom/navigator-userAgent-frozen.html
+
+        * page/cocoa/UserAgent.h:
+        * page/cocoa/UserAgent.mm:
+        (WebCore::versionPredatesFreeze): Helper function. Returns true for Version 10.13.3 or older.
+        (WebCore::systemMarketingVersionForUserAgentString):
+        (WebCore::userAgentBundleVersion):
+        (WebCore::userVisibleWebKitBundleVersionFromFullVersion): Deleted.
+        (WebCore::userAgentBundleVersionFromFullVersionString): Deleted.
+        * page/ios/UserAgentIOS.mm:
+        (WebCore::standardUserAgentWithApplicationName): Don't take the WebKit bundle version
+        as an argument, or pass it to the user agent string generator.
+        * page/mac/UserAgentMac.mm:
+        (WebCore::standardUserAgentWithApplicationName): Ditto. 
+
 2017-12-05  Matt Lewis  <[email protected]>
 
         Unreviewed, rolling out r225430.

Modified: trunk/Source/WebCore/page/cocoa/UserAgent.h (225561 => 225562)


--- trunk/Source/WebCore/page/cocoa/UserAgent.h	2017-12-06 01:47:29 UTC (rev 225561)
+++ trunk/Source/WebCore/page/cocoa/UserAgent.h	2017-12-06 01:59:53 UTC (rev 225562)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014 Apple Inc. All rights reserved.
+ * Copyright (C) 2014-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -30,10 +30,10 @@
 
 namespace WebCore {
 
-WEBCORE_EXPORT String standardUserAgentWithApplicationName(const String& applicationName, const String& webkitVersionString);
+WEBCORE_EXPORT String standardUserAgentWithApplicationName(const String& applicationName);
 
 String systemMarketingVersionForUserAgentString();
-String userAgentBundleVersionFromFullVersionString(const String&);
+String userAgentBundleVersion();
 
 }
 

Modified: trunk/Source/WebCore/page/cocoa/UserAgent.mm (225561 => 225562)


--- trunk/Source/WebCore/page/cocoa/UserAgent.mm	2017-12-06 01:47:29 UTC (rev 225561)
+++ trunk/Source/WebCore/page/cocoa/UserAgent.mm	2017-12-06 01:59:53 UTC (rev 225562)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014 Apple Inc. All rights reserved.
+ * Copyright (C) 2014-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -26,8 +26,6 @@
 #import "config.h"
 #import "UserAgent.h"
 
-#import "SystemVersion.h"
-
 namespace WebCore {
 
 String systemMarketingVersionForUserAgentString()
@@ -35,38 +33,22 @@
     // Use underscores instead of dots because when we first added the Mac OS X version to the user agent string
     // we were concerned about old DHTML libraries interpreting "4." as Netscape 4. That's no longer a concern for us
     // but we're sticking with the underscores for compatibility with the format used by older versions of Safari.
-    return [systemMarketingVersion() stringByReplacingOccurrencesOfString:@"." withString:@"_"];
+#if PLATFORM(MAC)
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300
+    return ASCIILiteral("10_13_4");
+#elif __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
+    return ASCIILiteral("10_12_6");
+#else
+    return ASCIILiteral("10_11_6");
+#endif
+#else
+    return ASCIILiteral("11_3");
+#endif
 }
 
-static NSString *userVisibleWebKitBundleVersionFromFullVersion(NSString *fullWebKitVersion)
+String userAgentBundleVersion()
 {
-    // If the version is longer than 3 digits then the leading digits represent the version of the OS. Our user agent
-    // string should not include the leading digits, so strip them off and report the rest as the version. <rdar://problem/4997547>
-    NSRange nonDigitRange = [fullWebKitVersion rangeOfCharacterFromSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]];
-    if (nonDigitRange.location == NSNotFound && fullWebKitVersion.length > 3)
-        return [fullWebKitVersion substringFromIndex:fullWebKitVersion.length - 3];
-    if (nonDigitRange.location != NSNotFound && nonDigitRange.location > 3)
-        return [fullWebKitVersion substringFromIndex:nonDigitRange.location - 3];
-    return fullWebKitVersion;
+    return ASCIILiteral("605.1.15");
 }
 
-String userAgentBundleVersionFromFullVersionString(const String& fullWebKitVersion)
-{
-    // We include at most three components of the bundle version in the user agent string.
-    NSString *bundleVersion = userVisibleWebKitBundleVersionFromFullVersion(fullWebKitVersion);
-    NSScanner *scanner = [NSScanner scannerWithString:bundleVersion];
-    NSInteger periodCount = 0;
-    while (true) {
-        if (![scanner scanUpToString:@"." intoString:nullptr] || scanner.isAtEnd)
-            return bundleVersion;
-
-        if (++periodCount == 3)
-            return [bundleVersion substringToIndex:scanner.scanLocation];
-
-        ++scanner.scanLocation;
-    }
-
-    ASSERT_NOT_REACHED();
-}
-
 } // namespace WebCore

Modified: trunk/Source/WebCore/page/ios/UserAgentIOS.mm (225561 => 225562)


--- trunk/Source/WebCore/page/ios/UserAgentIOS.mm	2017-12-06 01:47:29 UTC (rev 225561)
+++ trunk/Source/WebCore/page/ios/UserAgentIOS.mm	2017-12-06 01:59:53 UTC (rev 225562)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014 Apple Inc. All rights reserved.
+ * Copyright (C) 2014-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -77,7 +77,7 @@
     return name.autorelease();
 }
 
-String standardUserAgentWithApplicationName(const String& applicationName, const String& fullWebKitVersionString)
+String standardUserAgentWithApplicationName(const String& applicationName)
 {
     // Check to see if there is a user agent override for all WebKit clients.
     CFPropertyListRef override = CFPreferencesCopyAppValue(CFSTR("UserAgent"), CFSTR("com.apple.WebFoundation"));
@@ -88,7 +88,7 @@
     }
 
     // FIXME: We should implement this with String and/or StringBuilder instead.
-    NSString *webKitVersion = userAgentBundleVersionFromFullVersionString(fullWebKitVersionString);
+    NSString *webKitVersion = userAgentBundleVersion();
     NSString *osMarketingVersionString = systemMarketingVersionForUserAgentString();
     if (applicationName.isEmpty())
         return [NSString stringWithFormat:@"Mozilla/5.0 (%@; CPU %@ %@ like Mac OS X) AppleWebKit/%@ (KHTML, like Gecko)", deviceNameForUserAgent(), osNameForUserAgent(), osMarketingVersionString, webKitVersion];

Modified: trunk/Source/WebCore/page/mac/UserAgentMac.mm (225561 => 225562)


--- trunk/Source/WebCore/page/mac/UserAgentMac.mm	2017-12-06 01:47:29 UTC (rev 225561)
+++ trunk/Source/WebCore/page/mac/UserAgentMac.mm	2017-12-06 01:59:53 UTC (rev 225562)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014 Apple Inc. All rights reserved.
+ * Copyright (C) 2014-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -38,10 +38,10 @@
 #error Unknown architecture
 #endif
 
-String standardUserAgentWithApplicationName(const String& applicationName, const String& fullWebKitVersionString)
+String standardUserAgentWithApplicationName(const String& applicationName)
 {
     String osVersion = systemMarketingVersionForUserAgentString();
-    String webKitVersionString = userAgentBundleVersionFromFullVersionString(fullWebKitVersionString);
+    String webKitVersionString = userAgentBundleVersion();
 
     if (applicationName.isEmpty())
         return makeString("Mozilla/5.0 (Macintosh; " PROCESSOR " Mac OS X ", osVersion, ") AppleWebKit/", webKitVersionString, " (KHTML, like Gecko)");

Modified: trunk/Source/WebKit/ChangeLog (225561 => 225562)


--- trunk/Source/WebKit/ChangeLog	2017-12-06 01:47:29 UTC (rev 225561)
+++ trunk/Source/WebKit/ChangeLog	2017-12-06 01:59:53 UTC (rev 225562)
@@ -1,3 +1,19 @@
+2017-12-05  Brent Fulgham  <[email protected]>
+
+        Limit user agent versioning to an upper bound
+        https://bugs.webkit.org/show_bug.cgi?id=180365
+        <rdar://problem/34550617>
+
+        Reviewed by Joseph Pecoraro.
+
+        * UIProcess/ios/WebPageProxyIOS.mm:
+        (WebKit::WebPageProxy::standardUserAgent): Don't pass the WebKit bundle version when
+        creatin the User Agent string.
+        (WebKit::webKitBundleVersionString): Deleted.
+        * UIProcess/mac/WebPageProxyMac.mm:
+        (WebKit::WebPageProxy::standardUserAgent): Ditto.
+        (WebKit::webKitBundleVersionString): Deleted.
+
 2017-12-05  Alex Christensen  <[email protected]>
 
         Fix crash when loading a file URL that does not have a fileSystemPath representation

Modified: trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm (225561 => 225562)


--- trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm	2017-12-06 01:47:29 UTC (rev 225561)
+++ trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm	2017-12-06 01:59:53 UTC (rev 225562)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2012-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -68,14 +68,9 @@
 {
 }
 
-static String webKitBundleVersionString()
-{
-    return [[NSBundle bundleForClass:NSClassFromString(@"WKWebView")] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
-}
-
 String WebPageProxy::standardUserAgent(const String& applicationNameForUserAgent)
 {
-    return standardUserAgentWithApplicationName(applicationNameForUserAgent, webKitBundleVersionString());
+    return standardUserAgentWithApplicationName(applicationNameForUserAgent);
 }
 
 void WebPageProxy::getIsSpeaking(bool&)

Modified: trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm (225561 => 225562)


--- trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm	2017-12-06 01:47:29 UTC (rev 225561)
+++ trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm	2017-12-06 01:59:53 UTC (rev 225562)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2010-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -91,14 +91,9 @@
     setShouldUseImplicitRubberBandControl(clientExpectsLegacyImplicitRubberBandControl);
 }
 
-static String webKitBundleVersionString()
-{
-    return [[NSBundle bundleForClass:NSClassFromString(@"WKView")] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
-}
-
 String WebPageProxy::standardUserAgent(const String& applicationNameForUserAgent)
 {
-    return standardUserAgentWithApplicationName(applicationNameForUserAgent, webKitBundleVersionString());
+    return standardUserAgentWithApplicationName(applicationNameForUserAgent);
 }
 
 void WebPageProxy::getIsSpeaking(bool& isSpeaking)

Modified: trunk/Source/WebKitLegacy/mac/ChangeLog (225561 => 225562)


--- trunk/Source/WebKitLegacy/mac/ChangeLog	2017-12-06 01:47:29 UTC (rev 225561)
+++ trunk/Source/WebKitLegacy/mac/ChangeLog	2017-12-06 01:59:53 UTC (rev 225562)
@@ -1,3 +1,16 @@
+2017-12-05  Brent Fulgham  <[email protected]>
+
+        Limit user agent versioning to an upper bound
+        https://bugs.webkit.org/show_bug.cgi?id=180365
+        <rdar://problem/34550617>
+
+        Reviewed by Joseph Pecoraro.
+
+        * WebView/WebView.mm:
+        (+[WebView _standardUserAgentWithApplicationName:]): Don't pass the WebKit bundle version when
+        creating the User Agent string.
+        (webKitBundleVersionString): Deleted.
+
 2017-12-05  Andy Estes  <[email protected]>
 
         [Cocoa] Stop specifying TARGET_OS_EMBEDDED in postprocess-headers.sh's unifdef options

Modified: trunk/Source/WebKitLegacy/mac/WebView/WebView.mm (225561 => 225562)


--- trunk/Source/WebKitLegacy/mac/WebView/WebView.mm	2017-12-06 01:47:29 UTC (rev 225561)
+++ trunk/Source/WebKitLegacy/mac/WebView/WebView.mm	2017-12-06 01:59:53 UTC (rev 225562)
@@ -1132,14 +1132,9 @@
 
 @implementation WebView (WebPrivate)
 
-static String webKitBundleVersionString()
-{
-    return [[NSBundle bundleForClass:[WebView class]] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
-}
-
 + (NSString *)_standardUserAgentWithApplicationName:(NSString *)applicationName
 {
-    return standardUserAgentWithApplicationName(applicationName, webKitBundleVersionString());
+    return standardUserAgentWithApplicationName(applicationName);
 }
 
 #if PLATFORM(IOS)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to