Skip to content
Go to file

Latest commit


* While detecting Username and password in url we were not breaking the iteration if we find the :
This meanst that if there was a long substring of : then we will iterate till the end of the : string
and then restart the same iteration for the next :.
This fix breaks the usename and password detection when it encounters the next : thus breaking the look early
and backtracking less.

* Adding a test case for a valid URL between colons
173c6db 1

Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Url Detector

The url detector is a library created by the Linkedin Security Team to detect and extract urls in a long piece of text.

It is able to find and detect any urls such as:

Note: Keep in mind that for security purposes, its better to overdetect urls and check more against blacklists than to not detect a url that was submitted. As such, some things that we detect might not be urls but somewhat look like urls. Also, instead of complying with RFC 3986 (, we try to detect based on browser behavior, optimizing detection for urls that are visitable through the address bar of Chrome, Firefox, Internet Explorer, and Safari.

It is also able to identify the parts of the identified urls. For example, for the url:

  • Scheme - "http"
  • Username - "user"
  • Password - null
  • Host - ""
  • Port - 39000
  • Path - "/hello"
  • Query - "?boo=ff"
  • Fragment - "#frag"

How to Use:

Using the URL detector library is simple. Simply import the UrlDetector object and give it some options. In response, you will get a list of urls which were detected.

For example, the following code will find the url

    UrlDetector parser = new UrlDetector("hello this is a url", UrlDetectorOptions.Default);
    List<Url> found = parser.detect();

    for(Url url : found) {
        System.out.println("Scheme: " + url.getScheme());
        System.out.println("Host: " + url.getHost());
        System.out.println("Path: " + url.getPath());

Quote Matching and HTML

Depending on your input string, you may want to handle certain characters in a special way. For example if you are parsing HTML, you probably want to break out of things like quotes and brackets. For example, if your input looks like

<a href=""&gt;;/a>

You probably want to make sure that the quotes and brackets are extracted. For that reason, using UrlDetectorOptions will allow you to change the sensitivity level of detection based on your expected input type. This way you can detect instead of</a>.

In code this looks like:

    UrlDetector parser = new UrlDetector("<a href=""></a>", UrlDetectorOptions.HTML);
    List<Url> found = parser.detect();


This library was written by the security team and Linkedin when other options did not exist. Some of the primary authors are:

Third Party Dependencies


####Apache CommonsLang3: org.apache.commons:commons-lang3:3.1


Copyright 2015 LinkedIn Corp. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the license at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.


A Java library to detect and normalize URLs in text



No releases published


No packages published


You can’t perform that action at this time.