Skip to content

[WIP] ascanrules: Fix for XSS issues related to javascript context.#3838

Open
jokrsec wants to merge 4 commits intozaproxy:mainfrom
jokrsec:testing-parser
Open

[WIP] ascanrules: Fix for XSS issues related to javascript context.#3838
jokrsec wants to merge 4 commits intozaproxy:mainfrom
jokrsec:testing-parser

Conversation

@jokrsec
Copy link

@jokrsec jokrsec commented Jun 8, 2022

Fixes zaproxy/zaproxy#7212

Integrated a javascript parser to extract the contexts. Updated the scanner to fix the issues.

@kingthorin
Copy link
Member

Is some of this generated or third party code?
Does this increase coverage? (If so unit tests should be added to demonstrate the new coverage and ensure it isn't broken in the future.)

@thc202 thc202 changed the title ascanrules: Fix for XSS issues related to javascript context. [WIP] ascanrules: Fix for XSS issues related to javascript context. Jun 8, 2022
@jokrsec
Copy link
Author

jokrsec commented Jun 8, 2022

The parser code is generated by antlr. I'll add the unit tests for the fixed issues 🙂

@kingthorin
Copy link
Member

kingthorin commented Jun 8, 2022

The parser code is generated by antlr.

This should be noted somehow, so that people don't try to maintain the classes manually. (@thc202 advice/ideas on that front?)

I'll add the unit tests for the fixed issues

Great.

There's unfortunately also a conflict you're going to need to address. I think I mentioned on the other PR that I'd look at it but I haven't had a chance yet. The XSS scan rule was made less monolithic so hopefully adapting your changes isn't too bad/hard.

@psiinon
Copy link
Member

psiinon commented Jun 8, 2022

It does say // Generated from JavaScriptLexer.g4 by ANTLR 4.10.1 :)

@kingthorin
Copy link
Member

That's a good start, sorry I overlooked it. Should we exclude the license header from those then? (I think that will help it to stand out.)

@psiinon
Copy link
Member

psiinon commented Jun 8, 2022

FYI I've been chatting to @jokrhub about this, and will manually override the DCO check :)

@kingthorin
Copy link
Member

If the antlr files are generated we should also document the steps needed to update.

@lgtm-com

This comment was marked as resolved.

1 similar comment
@lgtm-com

This comment was marked as duplicate.

@jokrsec jokrsec requested review from kingthorin, ricekot and thc202 June 23, 2022 03:52
Copy link
Member

@kingthorin kingthorin left a comment

Choose a reason for hiding this comment

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

Looks good overall. The DCO and squash/fixup still need to be addressed. Plus there's one thing here that could probably be simplified.

@kingthorin
Copy link
Member

We spoke on slack, I understand you're having trouble getting an interactive rebase to work nicely. Don't worry, it isn't terribly straight forward and is daunting if you haven't done it successfully in the past.

If you can just confirm that you agree with https://developercertificate.org/ we can manually set it to pass.

@jokrsec
Copy link
Author

jokrsec commented Jun 24, 2022

We spoke on slack, I understand you're having trouble getting an interactive rebase to work nicely. Don't worry, it isn't terribly straight forward and is daunting if you haven't done it successfully in the past.

If you can just confirm that you agree with https://developercertificate.org/ we can manually set it to pass.

Yes I agree.

@kingthorin
Copy link
Member

image
Setting DCO pass and will on subsequent commits as well.

@thc202
Copy link
Member

thc202 commented Jun 24, 2022

We should add the grammar and a Gradle task to (re)generate the code.

@kingthorin
Copy link
Member

kingthorin commented Jun 24, 2022

@jokrhub if you can just add a comment with some details on how the code was generated we can discuss adding a gradle task 😀

@jokrsec
Copy link
Author

jokrsec commented Jun 24, 2022

Below are the steps to generate lexer and parser files using antlr:

  1. Download antlr jar file, javascript grammar files and base files for lexer and parser. Place them in the same folder.

     wget https://www.antlr.org/download/antlr-4.10.1-complete.jar
    
     wget https://raw.githubusercontent.com/antlr/grammars-v4/master/javascript/javascript/JavaScriptLexer.g4
    
     wget https://raw.githubusercontent.com/antlr/grammars-v4/master/javascript/javascript/JavaScriptParser.g4
    
     wget https://raw.githubusercontent.com/antlr/grammars-v4/master/javascript/javascript/Java/JavaScriptLexerBase.java
    
     wget https://raw.githubusercontent.com/antlr/grammars-v4/master/javascript/javascript/Java/JavaScriptParserBase.java
    
  2. Generate java files for lexer and parser

     java -jar antlr-4.10.1-complete.jar JavaScriptLexer.g4 JavaScriptParser.g4
    
  3. Choose java files among the generated files.

@kingthorin
Copy link
Member

Grr I don’t see the push here anymore, got the id? Or can you just push it again and I’ll deconflict things more carefully.

@kingthorin
Copy link
Member

Found it: 7beed33

@kingthorin
Copy link
Member

Restored.

@thc202
Copy link
Member

thc202 commented Jan 15, 2023

Thanks! Feel free to fix up if it looks sane.

@kingthorin
Copy link
Member

It does look sane. I still need to address earlier comments about logic changes and additional tests.

Which I intend to tackle but I need to take the time to figure out what the original logic was catching, write tests, then figure out why/how the logic was changed. (Unless @jokrhub or someone else has interest in tackling that.)

All that to say, there’s still more change coming that will probably also need to be flattened.

@thc202
Copy link
Member

thc202 commented Jan 17, 2023

Sounds good, I can take a look at adding the tests cases.

@kingthorin
Copy link
Member

Thanks, I'd appreciate that!

@thc202 thc202 force-pushed the testing-parser branch 2 times, most recently from 0d361a7 to 50a375a Compare August 1, 2023 09:30
jokrsec and others added 4 commits November 19, 2023 09:45
Signed-off-by: jokrhub <loganalex007@gmail.com>
Reduce code duplication, extract constants, remove unnecessary
comments.

Signed-off-by: thc202 <thc202@gmail.com>
Update to latest versions.
Exclude 3rd-party code from Error Prone to avoid the need to do manual
changes when updated.

Signed-off-by: thc202 <thc202@gmail.com>
Use the same listener for all parsers, it has no state.
Use the same exception since it's only used for control flow and do not
use an error where a runtime exception is enough.

Signed-off-by: thc202 <thc202@gmail.com>
@github-actions

This comment was marked as duplicate.

@github-actions

This comment was marked as duplicate.

@kingthorin
Copy link
Member

Rebased current

@github-actions

This comment was marked as duplicate.

@github-actions
Copy link

github-actions bot commented Aug 9, 2024

CLA Assistant Lite bot:
Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


1 out of 2 committers have signed the CLA.
@thc202
@jokrsec

@kingthorin
Copy link
Member

This is pending me fixing things after the rebase. Between the previous one and now another 10 param method was introduced so now that conflicts with these changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

Webseclab: Fix any 5 Reflected JavaScript issues

5 participants