ua-parser / uap-java Goto Github PK
View Code? Open in Web Editor NEWJava implementation of ua-parser
License: Other
Java implementation of ua-parser
License: Other
In order to remove yaml parsers from the uap-java
library, we could pre-process the yaml file from uap-core and generate a Map at compile-time.
This would remove the dependency on snakeyaml
, and increase the first-start time of the library.
Can this get all of the fields that the NodeJS version does?
Do they both use the same regexes.yaml?
If so, how hard would it be to update it to get the same data results?
For instance, some missing fields are:
ua.browser.version (just combine the major and minor, maybe patch results?)
ua.device.type (i.e. desktop, mobile, tablet, etc) (basically device category)
ua.device.model (i.e. iPhone, etc.) (for this I'm currently using device.family)
ua.os.version (just combine the major and minor, maybe patch results?)
ua.device.vendor (i.e. Apple, Microsoft, etc)
ua.cpu.architecture (i.e. AMD64, etc.)
Hi, Benjamin
Hi
I have used this ua parser for parsing user agents.
It is returning chrome for the Edge browser.
Can you please add support for the same.
Thanks.
Can we have a release of this to maven central? ua-core
has introduced detection of the chrome based IE, but sins then there has been no release of this library.
By following the instructions from the Readme the jar can't be built.
The uap-core is not a jar and there is no dependency that can be fetched.
uap-core is a submodule that contains metadata and it should be packed with the actual uap-java jar package.
Commit 36e3062 introduced this issue, left a comment there also.
Please amend the documentation or the build to have it working.
https://nvd.nist.gov/vuln/detail/CVE-2022-1471
Fixed in snakeyaml version 2.0
I have clone the project but getting below exception while executing the unit test:
org.yaml.snakeyaml.error.YAMLException: java.io.IOException: Stream closed
at org.yaml.snakeyaml.reader.StreamReader.update(StreamReader.java:198)
at org.yaml.snakeyaml.reader.StreamReader.(StreamReader.java:62)
at org.yaml.snakeyaml.Yaml.load(Yaml.java:411)
at ua_parser.Parser.initialize(Parser.java:69)
at ua_parser.Parser.(Parser.java:44)
at ua_parser.Parser.(Parser.java:40)
at ua_parser.ParserTest.initParser(ParserTest.java:43)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
Caused by: java.io.IOException: Stream closed
at java.io.PushbackInputStream.ensureOpen(PushbackInputStream.java:74)
at java.io.PushbackInputStream.read(PushbackInputStream.java:166)
at org.yaml.snakeyaml.reader.UnicodeReader.init(UnicodeReader.java:88)
at org.yaml.snakeyaml.reader.UnicodeReader.read(UnicodeReader.java:118)
at java.io.Reader.read(Reader.java:140)
at org.yaml.snakeyaml.reader.StreamReader.update(StreamReader.java:182)
... 29 more
I didn't find any regexes.yaml file in the source code. Am I missing something?
While working on a project using uap-java, I found it necessary to provide explicit instructions to Jackson for deserialization as there are no default constructors on the models in ua_parser (and correctly so.
This seemed like a common enough use case that I thought to offer a PR (#34).
What went wrong:
Could not resolve all dependencies for configuration ':crmweb:compile'.
Could not find group:uap-clj, module:uap-clj, version:1.3.1.
Required by:
com.myntra:crmweb:1.0
compile "uap-clj:uap-clj:1.3.1"
As we can see below, the code - regex: '(EdgiOS|EdgA)/(\d+)\.(\d+)\.(\d+)\.(\d+)' family_replacement: 'Edge Mobile'
map EdgiOS
as Edge Mobile
.
This works well when we have a user-agent like this Mozilla/5.0 (iPhone; CPU iPhone OS 17_1_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 EdgiOS/119.2151.65 Mobile/15E148 Safari/605.1.15
.
However, we received the user-agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/605.1.15 (KHTML, like Gecko) EdgiOS/118 Version/13.0.3 Safari/605.1.15
that was mapped wrongly as Safari 13.0.3
instead of Edge Mobile 118
.
Maybe I'm using the wrong version of something? What are the requirements for this code?
I thought it might have been related to this issue but it was merged already.
$ docker run -it --rm maven:3.3.3-jdk-9 bash -c 'git clone https://github.com/ua-parser/uap-java.git; cd uap-java; mvn package'
[dependencies redacted]
...
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running ua_parser.ParserTest
Tests run: 9, Failures: 0, Errors: 9, Skipped: 0, Time elapsed: 0.163 sec <<< FAILURE!
testInvalidConfigThrows(ua_parser.ParserTest) Time elapsed: 0.02 sec <<< ERROR!
org.yaml.snakeyaml.error.YAMLException: java.io.IOException: Stream closed
at org.yaml.snakeyaml.reader.StreamReader.update(StreamReader.java:198)
at org.yaml.snakeyaml.reader.StreamReader.<init>(StreamReader.java:62)
at org.yaml.snakeyaml.Yaml.load(Yaml.java:411)
at ua_parser.Parser.initialize(Parser.java:69)
at ua_parser.Parser.<init>(Parser.java:44)
at ua_parser.Parser.<init>(Parser.java:40)
at ua_parser.ParserTest.initParser(ParserTest.java:43)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(java.base@9-internal/Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(java.base@9-internal/NativeMethodAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(java.base@9-internal/DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(java.base@9-internal/Method.java:533)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(java.base@9-internal/Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(java.base@9-internal/NativeMethodAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(java.base@9-internal/DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(java.base@9-internal/Method.java:533)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Caused by: java.io.IOException: Stream closed
at java.io.PushbackInputStream.ensureOpen(java.base@9-internal/PushbackInputStream.java:75)
at java.io.PushbackInputStream.read(java.base@9-internal/PushbackInputStream.java:163)
at org.yaml.snakeyaml.reader.UnicodeReader.init(UnicodeReader.java:88)
at org.yaml.snakeyaml.reader.UnicodeReader.read(UnicodeReader.java:118)
at java.io.Reader.read(java.base@9-internal/Reader.java:140)
at org.yaml.snakeyaml.reader.StreamReader.update(StreamReader.java:182)
... 35 more
Many more failures exactly like that, i.e. org.yaml.snakeyaml.error.YAMLException: java.io.IOException: Stream closed
...
Running ua_parser.DeviceTest
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.024 sec
Results :
Tests in error:
testInvalidConfigThrows(ua_parser.ParserTest): java.io.IOException: Stream closed
testParseOS(ua_parser.ParserTest): java.io.IOException: Stream closed
testParseAdditionalOS(ua_parser.ParserTest): java.io.IOException: Stream closed
testParseDevice(ua_parser.ParserTest): java.io.IOException: Stream closed
testParseFirefox(ua_parser.ParserTest): java.io.IOException: Stream closed
testParsePGTS(ua_parser.ParserTest): java.io.IOException: Stream closed
testParseAll(ua_parser.ParserTest): java.io.IOException: Stream closed
testParseUserAgent(ua_parser.ParserTest): java.io.IOException: Stream closed
testReplacementQuoting(ua_parser.ParserTest): java.io.IOException: Stream closed
testCachedParseAll(ua_parser.CachingParserTest): java.io.IOException: Stream closed
testCachedReplacementQuoting(ua_parser.CachingParserTest): java.io.IOException: Stream closed
testCachedParseOS(ua_parser.CachingParserTest): java.io.IOException: Stream closed
testCachedParseUserAgent(ua_parser.CachingParserTest): java.io.IOException: Stream closed
testCachedParseAdditionalOS(ua_parser.CachingParserTest): java.io.IOException: Stream closed
testCachedParseDevice(ua_parser.CachingParserTest): java.io.IOException: Stream closed
testCachedParseFirefox(ua_parser.CachingParserTest): java.io.IOException: Stream closed
testCachedParsePGTS(ua_parser.CachingParserTest): java.io.IOException: Stream closed
testInvalidConfigThrows(ua_parser.CachingParserTest): java.io.IOException: Stream closed
testParseOS(ua_parser.CachingParserTest): java.io.IOException: Stream closed
testParseAdditionalOS(ua_parser.CachingParserTest): java.io.IOException: Stream closed
testParseDevice(ua_parser.CachingParserTest): java.io.IOException: Stream closed
testParseFirefox(ua_parser.CachingParserTest): java.io.IOException: Stream closed
testParsePGTS(ua_parser.CachingParserTest): java.io.IOException: Stream closed
testParseAll(ua_parser.CachingParserTest): java.io.IOException: Stream closed
testParseUserAgent(ua_parser.CachingParserTest): java.io.IOException: Stream closed
testReplacementQuoting(ua_parser.CachingParserTest): java.io.IOException: Stream closed
Tests run: 35, Failures: 0, Errors: 26, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 26.518 s
[INFO] Finished at: 2016-07-18T21:49:30+00:00
[INFO] Final Memory: 16M/54M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project ua-parser: There are test failures.
[ERROR]
[ERROR] Please refer to /uap-java/target/surefire-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
I must be missing something obvious because for me the latest doesn't build with cannot find symbol IOException
. I looked at the blame and the use was added 2 years ago and the imports haven't changed in 8 years:
https://github.com/ua-parser/uap-java/blame/master/src/main/java/ua_parser/CachingParser.java#L45
Where's my blind spot here?
-bash-4.1$ mvn package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building ua-parser 1.3.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ ua-parser ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/me/xx/lib/uap-java/../uap-core
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ ua-parser ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ ua-parser ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/me/xx/lib/uap-java/../uap-core/test_resources
[INFO] skip non existing resourceDirectory /home/me/xx/lib/uap-java/../uap-core/tests
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ ua-parser ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.10:test (default-test) @ ua-parser ---
[INFO] Surefire report directory: /home/me/xx/lib/uap-java/target/surefire-reports
Running ua_parser.CachingParserTest
Tests run: 17, Failures: 0, Errors: 17, Skipped: 0, Time elapsed: 0.125 sec <<< FAILURE!
Running ua_parser.DeviceTest
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.027 sec
Running ua_parser.ParserTest
Tests run: 9, Failures: 0, Errors: 9, Skipped: 0, Time elapsed: 0.013 sec <<< FAILURE!
Running ua_parser.UserAgentTest
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.021 sec
Running ua_parser.OSTest
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.026 sec
Results :
Tests in error:
testCachedReplacementQuoting(ua_parser.CachingParserTest): java.io.IOException: Stream closed
testCachedParseOS(ua_parser.CachingParserTest): java.io.IOException: Stream closed
testCachedParseAdditionalOS(ua_parser.CachingParserTest): java.io.IOException: Stream closed
testCachedParseDevice(ua_parser.CachingParserTest): java.io.IOException: Stream closed
testCachedParseFirefox(ua_parser.CachingParserTest): java.io.IOException: Stream closed
testCachedParsePGTS(ua_parser.CachingParserTest): java.io.IOException: Stream closed
testCachedParseAll(ua_parser.CachingParserTest): java.io.IOException: Stream closed
testCachedParseUserAgent(ua_parser.CachingParserTest): java.io.IOException: Stream closed
testInvalidConfigThrows(ua_parser.CachingParserTest): java.io.IOException: Stream closed
testParseUserAgent(ua_parser.CachingParserTest): java.io.IOException: Stream closed
testParseOS(ua_parser.CachingParserTest): java.io.IOException: Stream closed
testParseAdditionalOS(ua_parser.CachingParserTest): java.io.IOException: Stream closed
testParseDevice(ua_parser.CachingParserTest): java.io.IOException: Stream closed
testParseFirefox(ua_parser.CachingParserTest): java.io.IOException: Stream closed
testParsePGTS(ua_parser.CachingParserTest): java.io.IOException: Stream closed
testParseAll(ua_parser.CachingParserTest): java.io.IOException: Stream closed
testReplacementQuoting(ua_parser.CachingParserTest): java.io.IOException: Stream closed
testInvalidConfigThrows(ua_parser.ParserTest): java.io.IOException: Stream closed
testParseUserAgent(ua_parser.ParserTest): java.io.IOException: Stream closed
testParseOS(ua_parser.ParserTest): java.io.IOException: Stream closed
testParseAdditionalOS(ua_parser.ParserTest): java.io.IOException: Stream closed
testParseDevice(ua_parser.ParserTest): java.io.IOException: Stream closed
testParseFirefox(ua_parser.ParserTest): java.io.IOException: Stream closed
testParsePGTS(ua_parser.ParserTest): java.io.IOException: Stream closed
testParseAll(ua_parser.ParserTest): java.io.IOException: Stream closed
testReplacementQuoting(ua_parser.ParserTest): java.io.IOException: Stream closed
Tests run: 35, Failures: 0, Errors: 26, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.441s
[INFO] Finished at: Sun May 03 14:31:39 EDT 2015
[INFO] Final Memory: 10M/454M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.10:test (default-test) on project ua-parser: There are test failures.
[ERROR]
[ERROR] Please refer to /home/me/xx/lib/uap-java/target/surefire-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
We waited 8 months to get a fix for the Snake YAML dependency issue and for no good reason you bumped it to require Java 11. The app we need this for is not running on that version. Please release 1.6.1 and make running on Java 8 possible.
The existing snakeyaml library is listed as vulnerable to security vulnerabilities because it allows create of arbitrary java objects which could lead to remote code execution. org.snakeyaml:snakeyaml-engine seems to be a follow on from the existing snakeyaml library from the same developers but is able to parse YAML 1.2. Please could you consider using snakeyaml-engine to help developers working in organisations where automated security scanning for vulnerable dependencies causes friction between in house security teams and ordinary developers who happen to pull in uap-java as a dependency.
I want to used this lib by the maven central.
Can someone tell me whether the Parser
class is thread-safe?
If I'm using the Parser class in multiple places, what is the best we to do it?
Hi,
testOSFromYaml fails with
testParseOS(ua_parser.ParserTest) Time elapsed: 0.085 sec <<< FAILURE! java.lang.AssertionError: Mozilla/5.0 (Windows U; Win NT 5.0; en-US; rv:1.8.0.2) Gecko/20060308 Firefox/1.5.0.2 Expected: is <{"family": "Windows", "major": "NT", "minor": "", "patch": "", "patch_minor": ""}> got: <{"family": "Windows", "major": "$1", "minor": "", "patch": "", "patch_minor": ""}>
summary
Failed tests: testParseOS(ua_parser.ParserTest): Mozilla/5.0 (Windows U; Win NT 5.0; en-US; rv:1.8.0.2) Gecko/20060308 Firefox/1.5.0.2(..) testCachedParseOS(ua_parser.CachingParserTest): Mozilla/5.0 (Windows U; Win NT 5.0; en-US; rv:1.8.0.2) Gecko/20060308 Firefox/1.5.0.2(..) testParseOS(ua_parser.CachingParserTest): Mozilla/5.0 (Windows U; Win NT 5.0; en-US; rv:1.8.0.2) Gecko/20060308 Firefox/1.5.0.2(..)
I believe the issue is in
if (v1Replacement != null) {
v1 = v1Replacement;
} else if (groupCount >= 2) {
v1 = matcher.group(2);
}
line 108 of OSParser.java if the v1Replacement != null (which it isn't for the test case - it is $1), v1 is set to $1 which is incorrect. I think a fix may be something like
if (v1Replacement != null) {
if (v1Replacement.startsWith("$")) {
try {
int groupNo = Integer.parseInt(v1Replacement.substring(1));
v1 = (groupCount >= groupNo ? matcher.group(groupNo) : "");
} catch (Exception e) {
// move on and do nothing config error
}
} else {
v1 = v1Replacement;
}
} else if (groupCount >= 2) {
v1 = matcher.group(2);
}
Not sure about the coverage of all the other OS tests but this certainly fixes the issue with this failed tests and all other tests pass too.
IOException
is a checked exception, which forces all code using new Parser
to catch an "impossible" IOException
. A checked exception should be thrown in the case of a logically possible failure caused by external circumstances โ for example, file system or network errors. Since uap-java
reads its rules from a file on the classpath, and the syntax of the file is under the developer's control, any exception when reading this file indicates a programming error, which should be represented as an unchecked exception.
The constructor should catch the IOException
and wrap it in an AssertionError
(or maybe RuntimeException
).
ua =
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36 Edg/95.0.1020.44"
parse result
{"user_agent": {"family": "Edge", "major": "95", "minor": "0", "patch": "1020"}, "os": {"family": "Linux", "major": "", "minor": "", "patch": "", "patch_minor": ""}, "device": {"family": "Other"}}
Is the ua parsed rightly? the os major and os minor is null. and the device is other.
My browser is edge, os is ubuntu 18.x.
As I See it works if only change imports so we need to create a factory for Pattern/Matcher and adaptors
Do you have planning on using this project to create a library that integrates with something like the Spring Framework? (or caffeine
I think this is a good idea. ๐ค
Credits: @NavidMitchell
GHSA-3mc7-4q67-w48m found in org.yaml:snakeyaml (snakeyaml-1.29.jar) Version 1.29
Wasted about 10 minutes this morning trying to clone this and found that mvn package command failed - debugged and realized you need the regex file from the uap-core project. Then after a little digging came across a recent change to project has a git submodule in it.
It seems for this to work you need the clone to add --recursive
git clone --recursive https://github.com/ua-parser/uap-java.git
At least on a macbook with latest git and mvn via homebrew - maybe add this to readme?
As far as I know, the current 1.5.2 release of uap-java uses uap-core 0.12.0, which lags behind on the current version of uap-core (0.13.0).
Notable changes since uap-core 0.12.0 include improved support for iOS 13 user agents and initial support for iOS 14 user agents.
On the value MacOutlook/16.20.0.181208 (Intelx64 Mac OS X Version 10.14.4 (Build 18E226))
Caused by: java.lang.IndexOutOfBoundsException: No group 3
at java.util.regex.Matcher.group(Matcher.java:538)
at ua_parser.OSParser$OSPattern.getReplacement(OSParser.java:137)
at ua_parser.OSParser$OSPattern.match(OSParser.java:123)
at ua_parser.OSParser.parse(OSParser.java:58)
at ua_parser.Parser.parseOS(Parser.java:74)
at ua_parser.CachingParser.parseOS(CachingParser.java:114)
at ua_parser.Parser.parse(Parser.java:60)
at ua_parser.CachingParser.parse(CachingParser.java:56)
Expected: is <{"family": "Windows", "major": "NT", "minor": "", "patch": "", "patch_minor": ""}>
got: <{"family": "Windows", "major": "$1", "minor": "", "patch": "", "patch_minor": ""}>
at org.junit.Assert.assertThat(Assert.java:780)
at ua_parser.ParserTest.testOSFromYaml(ParserTest.java:139)
at ua_parser.ParserTest.testParseOS(ParserTest.java:53)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
The java.desktop
is a quite huge dependency for a parser, please consider avoiding this dependency or parse the Yaml at compile time (this improves performances too).
java.lang.NoClassDefFoundError: java/beans/IntrospectionException
at org.yaml.snakeyaml.representer.BaseRepresenter.getPropertyUtils(BaseRepresenter.java:202)
at org.yaml.snakeyaml.Yaml.initDumperOptions(Yaml.java:120)
at org.yaml.snakeyaml.Yaml.<init>(Yaml.java:113)
at org.yaml.snakeyaml.Yaml.<init>(Yaml.java:103)
at ua_parser.Parser.initialize(Parser.java:80)
at ua_parser.Parser.<init>(Parser.java:45)
...
Caused by: java.lang.ClassNotFoundException: java.beans.IntrospectionException
at java.base/java.net.URLClassLoader.findClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
... 19 common frames omitted
Hello,
I recently made some changes to UAP-Core to support DuckDuckGo's mobile browsers and was wondering if I could trouble you to perform a release, please?
Thanks in advance.
We would like to use the uap-java library in our OSGI-based application.
For this to work, the manifest file has to be extended with bundle information.
I will create a pull request for this change.
Thanks in advance,
Rob
patchMinor is not included in the UserAgent Parser. For Chrome browsers, the parser will not catch the full name of the UserAgent, i.e. (https://github.com/ua-parser/uap-core/blob/09e9ccca9fcfc4348ae9e89815135bafcd0676bb/tests/test_ua.yaml#L2579-L2584)
For 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.78 Safari/537.36', the patchMinor would be "78", but that would not be captured by our parser.
Is the exclusion of patchMinor
intentional for the UserAgent browser, or should that be added into the UserAgent class?
I believe there is an ongoing PR that's been out for this: #61
As we can see below, the code - regex: '(CriOS)/(\d+)\.(\d+)\.(\d+)\.(\d+)' family_replacement: 'Chrome Mobile iOS'
map CriOS
as Chrome Mobile iOS
.
This works well when we have a user-agent like this Mozilla/5.0 (iPhone; CPU iPhone OS 10_0_1 like Mac OS X) AppleWebKit/601.1 (KHTML, like Gecko) CriOS/53.0.2785.86 Mobile/14A403 Safari/601.1.46
.
However, we received the user-agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/118 Version/11.1.1 Safari/605.1.15
that was mapped wrongly as Safari 11.1.1
instead of Chrome Mobile iOS 118
.
The class CachingParser
uses a org.apache.commons.collections4.map.LRUMap
internally.
The JavaDoc clearly states:
Note that LRUMap is not synchronized and is not thread-safe. If you wish to use this map from multiple threads concurrently, you must use appropriate synchronization. The simplest approach is to wrap this map using Collections.synchronizedMap(Map). This class may throw NullPointerException's when accessed by concurrent threads.
I think it would be good to add a lock directly in the CachingParser
.
user-agent: PostmanRuntime/7.22.0
Expected: is <{"family": "Firefox OS", "major": "1", "minor": "0", "patch": "1", "patch_minor": ""}>
got: <{"family": "Firefox OS", "major": "1", "minor": "0", "patch": "", "patch_minor": ""}>
Currently class Device
only includes family
. We find that brand
is usually more accurate in both the parsed results and in reflecting the characteristic of the agent. So it's necessary to add these two fields which are already supported in other uap libs.
Clojure developers would find using this library a lot easier if it were published to Maven Central.
Would this require changing the package name to org.ua-parser
?
Please let me know if I can help to achieve this.
Hi,
a Remote Distributed Denial of Service vulnerability was found and fixed in the regexes of the core project.
For more details see:
https://www.x41-dsec.de/lab/advisories/x41-2018-009-uaparser/
https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-20164
Please publish a new release to the maven repository, that comprises the fixed regexes.
Regards
Achim
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.