mirror of
https://github.com/umami-software/umami.git
synced 2026-02-14 09:35:36 +01:00
Domain validation. Filter domain from referrers.
This commit is contained in:
parent
a9765c7ea7
commit
5a4cde854a
13 changed files with 51 additions and 23 deletions
|
|
@ -1,8 +1,8 @@
|
|||
import firstBy from 'thenby';
|
||||
import { BROWSERS, ISO_COUNTRIES, DEVICES } from './constants';
|
||||
import { removeTrailingSlash } from './format';
|
||||
import { removeTrailingSlash, getDomainName } from './url';
|
||||
|
||||
export const urlFilter = (data, { domain, raw }) => {
|
||||
export const urlFilter = (data, { raw }) => {
|
||||
const isValidUrl = url => {
|
||||
return url !== '' && !url.startsWith('#');
|
||||
};
|
||||
|
|
@ -30,7 +30,7 @@ export const urlFilter = (data, { domain, raw }) => {
|
|||
return obj;
|
||||
}
|
||||
|
||||
const url = cleanUrl(x.startsWith('/') ? `http://${domain}${x}` : x);
|
||||
const url = cleanUrl(`http://x${x}`);
|
||||
|
||||
if (url) {
|
||||
if (!obj[url]) {
|
||||
|
|
@ -49,7 +49,8 @@ export const urlFilter = (data, { domain, raw }) => {
|
|||
};
|
||||
|
||||
export const refFilter = (data, { domain, domainOnly, raw }) => {
|
||||
const regex = new RegExp(domain.startsWith('http') ? domain : `http[s]?://${domain}`);
|
||||
const domainName = getDomainName(domain);
|
||||
const regex = new RegExp(`http[s]?://${domainName}`);
|
||||
|
||||
const isValidRef = ref => {
|
||||
return ref !== '' && !ref.startsWith('/') && !ref.startsWith('#');
|
||||
|
|
@ -63,7 +64,7 @@ export const refFilter = (data, { domain, domainOnly, raw }) => {
|
|||
try {
|
||||
const { hostname, origin, pathname, searchParams, protocol } = new URL(url);
|
||||
|
||||
if (hostname === domain || regex.test(url)) {
|
||||
if (hostname === domainName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue