Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Check script tags for inline JS #48

Merged
merged 34 commits into from
Apr 9, 2024
Merged

feat: Check script tags for inline JS #48

merged 34 commits into from
Apr 9, 2024

Conversation

d3xter666
Copy link
Contributor

JIRA: CPOUI5FOUNDATION-826

@d3xter666 d3xter666 marked this pull request as draft March 25, 2024 13:04
@matz3 matz3 mentioned this pull request Mar 25, 2024
27 tasks
src/linter/html/linter.ts Outdated Show resolved Hide resolved
@d3xter666 d3xter666 marked this pull request as ready for review March 27, 2024 09:44
@d3xter666 d3xter666 requested a review from a team March 27, 2024 09:44
tsconfig.base.json Outdated Show resolved Hide resolved
src/detectors/transpilers/html/parser.ts Outdated Show resolved Hide resolved
src/detectors/typeChecker/index.ts Outdated Show resolved Hide resolved
src/linter/html/HtmlReporter.ts Outdated Show resolved Hide resolved
src/linter/html/HtmlReporter.ts Outdated Show resolved Hide resolved
src/linter/html/linter.ts Outdated Show resolved Hide resolved
tsconfig.base.json Outdated Show resolved Hide resolved
@d3xter666 d3xter666 requested a review from RandomByte April 3, 2024 13:53
src/detectors/typeChecker/index.ts Show resolved Hide resolved
src/detectors/typeChecker/index.ts Outdated Show resolved Hide resolved
src/linter/html/linter.ts Outdated Show resolved Hide resolved
@matz3 matz3 requested a review from a team April 5, 2024 12:49
RandomByte
RandomByte previously approved these changes Apr 8, 2024
Copy link
Member

@RandomByte RandomByte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type#attribute_is_not_set_default_an_empty_string_or_a_javascript_mime_type
return attr.name.value !== "type" ||
(attr.name.value === "type" &&
(attr.value.value === "" || attr.value.value === "text/javascript"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the scope of SAPUI5, I find ~180 occurrences of the legacy MIME type application/javascript. Maybe we should include that one as well? The other legacy types, I didn't find.

According to https://mimesniff.spec.whatwg.org/#javascript-mime-type-essence-match, the MIME types are case insensitive. I don't expect the SAX parser to normalize attribute values, so the check maybe should be case insensitive.

Last but not least: we most likely won't process scripts of type module any time soon, but the check for inline scripts could complain about them already (if they're inline)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @codeworrior !

I have added the case insensitive checks and also the application/javascript type.

Regarding the module type, currently it's being ignored as we check only for missing type property or against a list of hardcoded, case insensitive (already, thanks!) types.

I have added type="module" to the test cases

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codeworrior's comment wasn't fully addressed, right? I also agree that the check should complain about type="module", as it is also relevant for CSP unsafe-inline.

In addition, a <script> tag with a "src" attribute and a comment (or even code) as content is falsely reported as finding. Browsers (tested with Chrome only) ignore the script tag content in case a "src" attribute is provided (even without a value).

<script src="foo.js"> // should not be reported as it is not a CSP violation
</script>
<script src> // should also not be reported as it is not a CSP violation
console.log("this code won't run");
</script>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missunderstood it. However, I have addressed the changes in the following PR: #70

@d3xter666 d3xter666 force-pushed the check-script-tags branch from a7c520b to 93495c6 Compare April 9, 2024 13:21
@d3xter666 d3xter666 merged commit 70b719a into main Apr 9, 2024
17 checks passed
@d3xter666 d3xter666 deleted the check-script-tags branch April 9, 2024 17:33
@openui5bot openui5bot mentioned this pull request Apr 9, 2024
d3xter666 added a commit that referenced this pull request Apr 12, 2024
…r checks (#70)

This change addresses the following comments:
#48 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants