Skip to content

Commit 3b61180

Browse files
committed
AG-41531 Improve 'href-sanitizer ' — support uBO arguments. #493
Squashed commit of the following: commit 13e2ec1 Author: Adam Wróblewski <[email protected]> Date: Wed Aug 20 11:26:46 2025 +0200 Add alias `-base64` for `base64decode` in `href-sanitizer` scriptlet
1 parent 61bb272 commit 3b61180

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ The format is based on [Keep a Changelog], and this project adheres to [Semantic
1010
<!-- TODO: change `@added unknown` tag due to the actual version -->
1111
<!-- during new scriptlets or redirects releasing -->
1212

13+
## [Unreleased]
14+
15+
### Added
16+
17+
- `-base64` as an alias of `base64decode` in `href-sanitizer` scriptlet [#493].
18+
19+
[Unreleased]: https://github.com/AdguardTeam/Scriptlets/compare/v2.2.9...HEAD
20+
[#493]: https://github.com/AdguardTeam/Scriptlets/issues/493
21+
1322
## [v2.2.9] - 2025-08-14
1423

1524
### Added

src/scriptlets/href-sanitizer.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { type Source } from './scriptlets';
3232
* - `?<parameter-name>` copy the value from URL parameter `parameter-name` of the same element's `href` attribute.
3333
* - `transform` — optional, defaults to no transforming. Possible values:
3434
* - `base64decode` — decode the base64 string from specified attribute.
35+
* `-base64` can be used as an alias.
3536
* - `removeHash` — remove the hash from the URL.
3637
* - `removeParam[:<parameters>]` — remove the specified parameters from the URL,
3738
* where `<parameters>` is a comma-separated list of parameter names;
@@ -183,7 +184,10 @@ export function hrefSanitizer(
183184
}
184185

185186
// transform markers
186-
const BASE64_DECODE_TRANSFORM_MARKER = 'base64decode';
187+
const BASE64_DECODE_TRANSFORM_MARKER = new Set([
188+
'base64decode',
189+
'-base64',
190+
]);
187191
const REMOVE_HASH_TRANSFORM_MARKER = 'removeHash';
188192
const REMOVE_PARAM_TRANSFORM_MARKER = 'removeParam';
189193
// separator markers
@@ -510,7 +514,7 @@ export function hrefSanitizer(
510514
// apply transform if specified
511515
if (transform) {
512516
switch (true) {
513-
case transform === BASE64_DECODE_TRANSFORM_MARKER:
517+
case BASE64_DECODE_TRANSFORM_MARKER.has(transform):
514518
newHref = base64Decode(newHref);
515519
break;
516520
case transform === REMOVE_HASH_TRANSFORM_MARKER:

tests/scriptlets/href-sanitizer.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,18 @@ test('Sanitize href - base64 where link decoded in object in search query ', (as
214214
assert.strictEqual(window.hit, 'FIRED');
215215
});
216216

217+
test('Sanitize href - decode base64 string in href attribute - test for alias "-base64"', (assert) => {
218+
const expectedHref = 'http://example.com/?v=123';
219+
const hrefWithBase64 = 'http://www.foo.com/out/?aHR0cDovL2V4YW1wbGUuY29tLz92PTEyMw==';
220+
const elem = createElem(hrefWithBase64);
221+
const selector = 'a[href*="out/?"]';
222+
const scriptletArgs = [selector, '[href]', '-base64'];
223+
runScriptlet(name, scriptletArgs);
224+
225+
assert.strictEqual(elem.getAttribute('href'), expectedHref, 'href has been sanitized and base64 was decoded');
226+
assert.strictEqual(window.hit, 'FIRED');
227+
});
228+
217229
test('Sanitize href - text content', (assert) => {
218230
const expectedHref = 'https://example.org/';
219231
const elem = createElem('https://example.com/foo?redirect=https%3A%2F%2Fexample.org%2F', expectedHref);

0 commit comments

Comments
 (0)