11const pollingRegex = / s d k \/ e v a l x \/ [ ^ / ] + \/ c o n t e x t s \/ (?< context > [ ^ / ? ] * ) \? ? .* ?/ ;
22const streamingREgex = / \/ e v a l \/ [ ^ / ] + \/ (?< context > [ ^ / ? ] * ) \? ? .* ?/ ;
33
4+ /**
5+ * Filter which redacts user information (auth) from a URL.
6+ *
7+ * If a username/password is present, then they are replaced with 'redacted'.
8+ * Authority reference: https://developer.mozilla.org/en-US/docs/Web/URI/Authority
9+ *
10+ * @param url URL to filter.
11+ * @returns A filtered URL.
12+ */
13+ function authorityUrlFilter ( url : string ) : string {
14+ // This will work in browser environments, but in the future we may want to consider an approach
15+ // which doesn't rely on the browser's URL parsing. This is because other environments we may
16+ // want to target, such as ReactNative, may not have as robust URL parsing.
17+ const urlObj = new URL ( url ) ;
18+ let hadAuth = false ;
19+ if ( urlObj . username ) {
20+ urlObj . username = 'redacted' ;
21+ hadAuth = true ;
22+ }
23+ if ( urlObj . password ) {
24+ urlObj . password = 'redacted' ;
25+ hadAuth = true ;
26+ }
27+ if ( hadAuth ) {
28+ return urlObj . toString ( ) ;
29+ }
30+ // If there was no auth information, then we don't need to modify the URL.
31+ return url ;
32+ }
33+
434/**
535 * Filter which removes context information for browser JavaScript endpoints.
636 *
737 * @param url URL to filter.
838 * @returns A filtered URL.
939 */
10- export default function defaultUrlFilter ( url : string ) : string {
40+ function ldUrlFilter ( url : string ) : string {
1141 // TODO: Maybe we consider a way to identify LD requests so they can be filtered without
1242 // regular expressions.
1343
@@ -27,3 +57,13 @@ export default function defaultUrlFilter(url: string): string {
2757 }
2858 return url ;
2959}
60+
61+ /**
62+ * Filter which redacts user information and removes context information for browser JavaScript endpoints.
63+ *
64+ * @param url URL to filter.
65+ * @returns A filtered URL.
66+ */
67+ export default function defaultUrlFilter ( url : string ) : string {
68+ return ldUrlFilter ( authorityUrlFilter ( url ) ) ;
69+ }
0 commit comments