Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9470f59
feat(biome_js_analyze): implement noScriptUrl rule
ruidosujeira Nov 24, 2025
a5e221d
feat(biome_js_analyze): implement noScriptUrl rule
ruidosujeira Nov 24, 2025
ba19a93
[autofix.ci] apply automated fixes
autofix-ci[bot] Nov 24, 2025
335b6fa
chore(lint): update noScriptUrl severity and snapshots
ruidosujeira Nov 24, 2025
1ac0f42
chore(security/noScriptUrl): resolve rebase conflict, enforce Severit…
ruidosujeira Nov 24, 2025
3976669
[autofix.ci] apply automated fixes
autofix-ci[bot] Nov 24, 2025
cfe9818
feat(js-analyze): add noScriptUrl rule to disallow 'javascript:' URLs…
ruidosujeira Nov 25, 2025
5e5c305
[autofix.ci] apply automated fixes
autofix-ci[bot] Nov 25, 2025
60d6fc8
feat(security): add noScriptUrl lint rule to detect and error on java…
ruidosujeira Nov 25, 2025
5218579
Update .changeset/add-no-script-url-rule.md
ruidosujeira Nov 25, 2025
a708f90
test: run and update snapshots; chore: move noScriptUrl to nursery, a…
ruidosujeira Nov 26, 2025
c00c728
Apply suggestion from @ematipico
ruidosujeira Nov 26, 2025
9145019
fix(security): register noScriptUrl diagnostic category and fix clipp…
ruidosujeira Nov 26, 2025
5fc2b33
[autofix.ci] apply automated fixes
autofix-ci[bot] Nov 26, 2025
ab3714c
Merge branch 'main' into feat/add-no-script-url-rule
ruidosujeira Nov 27, 2025
1867fd9
[autofix.ci] apply automated fixes
autofix-ci[bot] Nov 27, 2025
0587bd3
chore(changeset): update changeset to remove duplicate line and short…
ruidosujeira Nov 27, 2025
e1fe8dd
chore(changeset): commit latest changeset adjustment
ruidosujeira Nov 27, 2025
0358506
chore(changeset): commit latest changes before push
ruidosujeira Nov 27, 2025
1879ed7
refactor: apply review feedback for noScriptUrl rule
ruidosujeira Nov 27, 2025
726b356
Merge branch 'main' into feat/add-no-script-url-rule
ruidosujeira Nov 27, 2025
a576948
[autofix.ci] apply automated fixes
autofix-ci[bot] Nov 27, 2025
0201aaa
fix(noScriptUrl): remove security variant, use biome_rule_options and…
ruidosujeira Nov 27, 2025
f6d8dd7
[autofix.ci] apply automated fixes
autofix-ci[bot] Nov 27, 2025
70c22e5
Merge branch 'main' into feat/add-no-script-url-rule
ruidosujeira Dec 7, 2025
10a82fe
Merge branch 'main' into feat/add-no-script-url-rule
Netail Dec 7, 2025
900c708
fix: cicd
Netail Dec 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/add-no-script-url-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@biomejs/biome": patch
---
Added the nursery rule [`noScriptUrl`](https://biomejs.dev/linter/rules/no-script-url/).

This rule disallows the use of `javascript:` URLs, which are considered a form of `eval` and can pose security risks such as XSS vulnerabilities.

```jsx
<a href="javascript:alert('XSS')">Click me</a>
```
60 changes: 60 additions & 0 deletions crates/biome_cli/src/execute/migrate/eslint_any_rule_to_biome.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

194 changes: 108 additions & 86 deletions crates/biome_configuration/src/analyzer/linter/rules.rs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions crates/biome_diagnostics_categories/src/categories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ define_categories! {
"lint/security/noDangerouslySetInnerHtml": "https://biomejs.dev/linter/rules/no-dangerously-set-inner-html",
"lint/security/noDangerouslySetInnerHtmlWithChildren": "https://biomejs.dev/linter/rules/no-dangerously-set-inner-html-with-children",
"lint/security/noGlobalEval": "https://biomejs.dev/linter/rules/no-global-eval",
"lint/nursery/noScriptUrl": "https://biomejs.dev/linter/rules/no-script-url",
"lint/security/noSecrets": "https://biomejs.dev/linter/rules/no-secrets",
"lint/style/noCommonJs": "https://biomejs.dev/linter/rules/no-common-js",
"lint/style/noDefaultExport": "https://biomejs.dev/linter/rules/no-default-export",
Expand Down
3 changes: 2 additions & 1 deletion crates/biome_html_analyze/src/lint/nursery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! Generated file, do not edit by hand, see `xtask/codegen`

use biome_analyze::declare_lint_group;
pub mod no_script_url;
pub mod no_sync_scripts;
pub mod no_vue_v_if_with_v_for;
pub mod use_vue_hyphenated_attributes;
Expand All @@ -13,4 +14,4 @@ pub mod use_vue_valid_v_html;
pub mod use_vue_valid_v_if;
pub mod use_vue_valid_v_on;
pub mod use_vue_valid_v_text;
declare_lint_group! { pub Nursery { name : "nursery" , rules : [self :: no_sync_scripts :: NoSyncScripts , self :: no_vue_v_if_with_v_for :: NoVueVIfWithVFor , self :: use_vue_hyphenated_attributes :: UseVueHyphenatedAttributes , self :: use_vue_valid_v_bind :: UseVueValidVBind , self :: use_vue_valid_v_else :: UseVueValidVElse , self :: use_vue_valid_v_else_if :: UseVueValidVElseIf , self :: use_vue_valid_v_html :: UseVueValidVHtml , self :: use_vue_valid_v_if :: UseVueValidVIf , self :: use_vue_valid_v_on :: UseVueValidVOn , self :: use_vue_valid_v_text :: UseVueValidVText ,] } }
declare_lint_group! { pub Nursery { name : "nursery" , rules : [self :: no_script_url :: NoScriptUrl , self :: no_sync_scripts :: NoSyncScripts , self :: no_vue_v_if_with_v_for :: NoVueVIfWithVFor , self :: use_vue_hyphenated_attributes :: UseVueHyphenatedAttributes , self :: use_vue_valid_v_bind :: UseVueValidVBind , self :: use_vue_valid_v_else :: UseVueValidVElse , self :: use_vue_valid_v_else_if :: UseVueValidVElseIf , self :: use_vue_valid_v_html :: UseVueValidVHtml , self :: use_vue_valid_v_if :: UseVueValidVIf , self :: use_vue_valid_v_on :: UseVueValidVOn , self :: use_vue_valid_v_text :: UseVueValidVText ,] } }
106 changes: 106 additions & 0 deletions crates/biome_html_analyze/src/lint/nursery/no_script_url.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
use biome_analyze::{
Ast, Rule, RuleDiagnostic, RuleSource, context::RuleContext, declare_lint_rule,
};
use biome_console::markup;
use biome_diagnostics::Severity;
use biome_html_syntax::{AnyHtmlAttributeInitializer, HtmlOpeningElement, inner_string_text};
use biome_rowan::{AstNode, TextRange};
use biome_rule_options::no_script_url::NoScriptUrlOptions;
use biome_string_case::StrOnlyExtension;

declare_lint_rule! {
/// Disallow `javascript:` URLs in HTML.
///
/// Using `javascript:` URLs is considered a form of `eval` and can be a security risk.
/// These URLs can execute arbitrary JavaScript code, which can lead to cross-site scripting (XSS) vulnerabilities.
///
/// ## Examples
///
/// ### Invalid
///
/// ```html,expect_diagnostic
/// <a href="javascript:void(0)">Click me</a>
/// ```
///
/// ```html,expect_diagnostic
/// <a href="javascript:alert('XSS')">Click me</a>
/// ```
///
/// ### Valid
///
/// ```html
/// <a href="https://example.com">Click me</a>
/// <a href="/path/to/page">Click me</a>
/// <a href="#section">Click me</a>
/// <span href="javascript:void(0)">Not a real href</span>
/// ```
///
pub NoScriptUrl {
version: "next",
name: "noScriptUrl",
language: "html",
// Show equivalents from related ecosystems
sources: &[
RuleSource::Eslint("no-script-url").same(),
RuleSource::EslintReact("jsx-no-script-url").same(),
RuleSource::EslintQwik("jsx-no-script-url").same(),
RuleSource::EslintSolid("jsx-no-script-url").same(),
RuleSource::EslintReactXyz("dom-no-script-url").same(),
],
recommended: true,
severity: Severity::Error,
}
}

impl Rule for NoScriptUrl {
type Query = Ast<HtmlOpeningElement>;
type State = TextRange;
type Signals = Option<Self::State>;
type Options = NoScriptUrlOptions;

fn run(ctx: &RuleContext<Self>) -> Option<Self::State> {
let element = ctx.query();

// Only check <a> elements for HTML (unlike JSX where components/custom elements exist)
let name = element.name().ok()?;
let token = name.value_token().ok()?;
let tag = token.text_trimmed();
if !tag.eq_ignore_ascii_case("a") {
return None;
}

let attrs = element.attributes();
let attr = attrs.find_by_name("href")?;
let initializer = attr.initializer()?;
let value = initializer.value().ok()?;

if let AnyHtmlAttributeInitializer::HtmlString(html_string) = value
&& let Ok(token) = html_string.value_token()
{
let inner = inner_string_text(&token);
if inner.trim().to_lowercase_cow().starts_with("javascript:") {
return Some(initializer.range());
}
}

None
}

fn diagnostic(_ctx: &RuleContext<Self>, range: &Self::State) -> Option<RuleDiagnostic> {
Some(
RuleDiagnostic::new(
rule_category!(),
*range,
markup! {
"Avoid using "<Emphasis>"javascript:"</Emphasis>" URLs, as they can be a security risk."
},
)
.note(markup! {
"Using "<Emphasis>"javascript:"</Emphasis>" URLs can lead to security vulnerabilities such as cross-site scripting (XSS)."
})
.note(markup! {
"Consider using regular URLs, or if you need to handle click events, use event handlers instead."
}),
)
}
}
4 changes: 2 additions & 2 deletions crates/biome_html_analyze/tests/spec_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use camino::Utf8Path;
use std::ops::Deref;
use std::{fs::read_to_string, slice};

tests_macros::gen_tests! {"tests/specs/**/*.{html,vue,json,jsonc}", crate::run_test, "module"}
tests_macros::gen_tests! {"tests/suppression/**/*.{html,vue,json,jsonc}", crate::run_suppression_test, "module"}
tests_macros::gen_tests! {"tests/specs/**/*.{html,vue,astro,svelte,json,jsonc}", crate::run_test, "module"}
tests_macros::gen_tests! {"tests/suppression/**/*.{html,vue,astro,svelte,json,jsonc}", crate::run_suppression_test, "module"}

fn run_test(input: &'static str, _: &str, _: &str, _: &str) {
register_leak_checker();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
// Astro invalid cases - should trigger the rule
---

<a href="javascript:void(0)">Void</a>
<a href=" javascript:prompt('XSS') ">Prompt</a>
<a href="JAVASCRIPT:doSomething()">Uppercase</a>
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
source: crates/biome_html_analyze/tests/spec_tests.rs
expression: invalid.astro
---
# Input
```html
---
// Astro invalid cases - should trigger the rule
---

<a href="javascript:void(0)">Void</a>
<a href=" javascript:prompt('XSS') ">Prompt</a>
<a href="JAVASCRIPT:doSomething()">Uppercase</a>

```

# Diagnostics
```
invalid.astro:5:8 lint/nursery/noScriptUrl ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× Avoid using javascript: URLs, as they can be a security risk.

3 │ ---
4 │
> 5 │ <a href="javascript:void(0)">Void</a>
│ ^^^^^^^^^^^^^^^^^^^^^
6 │ <a href=" javascript:prompt('XSS') ">Prompt</a>
7 │ <a href="JAVASCRIPT:doSomething()">Uppercase</a>

i Using javascript: URLs can lead to security vulnerabilities such as cross-site scripting (XSS).

i Consider using regular URLs, or if you need to handle click events, use event handlers instead.


```

```
invalid.astro:6:8 lint/nursery/noScriptUrl ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× Avoid using javascript: URLs, as they can be a security risk.

5 │ <a href="javascript:void(0)">Void</a>
> 6 │ <a href=" javascript:prompt('XSS') ">Prompt</a>
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7 │ <a href="JAVASCRIPT:doSomething()">Uppercase</a>
8 │

i Using javascript: URLs can lead to security vulnerabilities such as cross-site scripting (XSS).

i Consider using regular URLs, or if you need to handle click events, use event handlers instead.


```

```
invalid.astro:7:8 lint/nursery/noScriptUrl ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× Avoid using javascript: URLs, as they can be a security risk.

5 │ <a href="javascript:void(0)">Void</a>
6 │ <a href=" javascript:prompt('XSS') ">Prompt</a>
> 7 │ <a href="JAVASCRIPT:doSomething()">Uppercase</a>
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^
8 │

i Using javascript: URLs can lead to security vulnerabilities such as cross-site scripting (XSS).

i Consider using regular URLs, or if you need to handle click events, use event handlers instead.


```
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!-- Invalid cases - should trigger the rule -->

<a href="javascript:void(0)">Link</a>

<a href="javascript:alert('XSS')">Link</a>

<a href=" javascript:void(0)">Link</a>

<a href="JAVASCRIPT:void(0)">Link</a>
Loading