microsoft / microsoft/DevSkim

Support for HTML (see attached example rule)

Open
#746 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C#
Stars
1k
Forks
131
Avg merge
1m
Merged PRs (30d)
1

Description

I would like to see support for HTML. Here is a working example DevSkim detection rule based of XML instead.

[
    {
        "name": "HTML_A_Tag_With_TargetBlank_Without_NoOpener",
        "id": "html_a_targetblank_noopener",
        "description": "Detects HTML <a> tags with target='_blank' that do not have the 'noopener' attribute in their rel, which can pose security risks.",
        "recommendation": "Add 'noopener' to the rel attribute of the HTML <a> tag.",
        "tags": ["security", "html", "a-tag", "noopener"],
        "severity": "BestPractice",
        "confidence": "high",
        "applies_to": ["xml"],
        "patterns": [
            {
                "pattern": "<a\\b(?=[^>]*target\\s*=\\s*[\"']_blank[\"'])(?!.*rel\\s*=\\s*[\"'][^\"']*noopener[^\"']*[\"'])[^>]*>",
                "type": "regex",
                "_comment": "Matches <a> tags with target='_blank' and without 'noopener' in rel attribute."
            }
        ]
    }
]

Test file

    <a href="https://example.com" target="_blank">Unsafe Link</a>
    <a href="https://example.com" rel="noreferrer" target="_blank">Unsafe Link</a>
    <a href="https://example.com" rel="" target="_blank">Unsafe Link</a>
    <a href="https://example.com">Safe Link</a>
    <a href="https://example.com" rel="noopener" target="_blank">Safe Link</a>
    <a href="https://example.com" rel="noopener noreferrer" target="_blank">Safe Link</a>

Perhaps this can be easily done with the already existing XML support.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the existing XML support and compare its rule handling with the supplied DevSkim JSON rule and HTML test cases. Add HTML coverage for the target="_blank" and rel="noopener" examples, then verify that unsafe links are detected and safe links are not.

Written by the indexing model from the issue text.

Assessment

Tech stack
html, xml
Domain
security, tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.