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

add a JellyVerifier for inline javascript and style tags #4049

Merged
merged 1 commit into from
Aug 26, 2024

Conversation

mawinter69
Copy link
Contributor

@mawinter69 mawinter69 commented Aug 26, 2024

The JellyVerifier checks for several kinds of inline javascript and style usages which are not CSP compliant.
Following checks are implement

  • inline style tags
  • script tags without src attribute that are not of type application/json
  • onclick attribute in namespaced element (this is an indicator that the deprecated onclick attribute is used that a few jellies in core support, e.g. f:radio), logged as warning
  • all attributes starting with on in tags without a namespace (Those are typically html elements), logged as warning
  • usage of checkUrl without checkDependsOn

Potentially some check might produce false positives.

Tested against issue 3310 which currently uses inline script and style.
Tested against 4024 it found usages of onclick attributes

Added unit tests that verifies all checks.

fixes #3770

The JellyVerifier checks for several kinds of inline javascript and
style usages which are not CSP compliant.
Following checks are implement
- inline style tags
- script tags without `src` attribute that are not of type `application/json`
- `onclick` attribute in namespaced element (this is an indicator that
  the deprecated onclick attribute is used that a few jelly taglibs in
  core support, e.g. f:radio), logged as warning
- all attributes starting with `on` in tags without a namespace (Those
  are typically html elements), logged as warning
- usage of `checkUrl` without `checkDependsOn`

Potentially some check might produce false positives.

Tested against issue 3310 which currently uses inline script and style.

Added unit tests that verifies all checks.
@mawinter69 mawinter69 requested a review from a team as a code owner August 26, 2024 08:21
@mawinter69
Copy link
Contributor Author

@timja @NotMyFault

@mawinter69
Copy link
Contributor Author

I think once we have core and majority of plugins CSP compliant we should consider moving some or all of these checks to a maven plugin to ensure that nobody accidently reintroduces inline stuff

@timja
Copy link
Member

timja commented Aug 26, 2024

I think once we have core and majority of plugins CSP compliant we should consider moving some or all of these checks to a maven plugin to ensure that nobody accidently reintroduces inline stuff

This is where the existing ones are I believe: https://github.com/jenkinsci/jenkins-test-harness/blob/b09ba623b3479730c0c340b9077f7251cc97c927/src/main/java/org/jvnet/hudson/test/JellyTestSuiteBuilder.java

Copy link
Member

@timja timja left a comment

Choose a reason for hiding this comment

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

Thanks! Tests looks great

@timja timja merged commit 5dde4b7 into jenkins-infra:master Aug 26, 2024
3 checks passed
Copy link
Member

@timja timja left a comment

Choose a reason for hiding this comment

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

I wonder whether

needs adapting to only add needs-fix on errors.

see #4024 (comment)

currently it would add needs-fix if only an info was added.

Generally all the hosting issues that appear are errors so we haven't really came across this, I think the warnings are more to do with how the bot ran e.g. can't find a gradle file is something wrong with the project setup

private static final Logger LOGGER = LoggerFactory.getLogger(JellyVerifier.class);
private static final String INLINE_STYLE = "The jelly file %s contains an inline `<style>` tag";
private static final String INLINE_SCRIPT = "The jelly file %s contains a `<script>` tag with inline javascript.";
private static final String INLINE_SCRIPT_METHOD = "The jelly file %s potentially uses inline javascript attribute `%s`";
Copy link
Member

Choose a reason for hiding this comment

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

Could these file paths be a link to GitHub?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes

@mawinter69 mawinter69 mentioned this pull request Aug 26, 2024
mawinter69 added a commit to mawinter69/jenkins-test-harness that referenced this pull request Oct 30, 2024
Detects usage of inline event handlers like onclick, usage of script
elements (except for json type), usage of checkUrl without
checkDependsOn

Same as
jenkins-infra/repository-permissions-updater#4049
but for maven builds
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.

Scan for inline javascript in jelly files
2 participants