Skip to content

Conversation

@jorgectf
Copy link
Contributor

No description provided.

Co-authored-by: Kevin Stubbings <Kwstubbs@users.noreply.github.com>
@jorgectf jorgectf requested a review from a team as a code owner June 29, 2023 17:18
@jorgectf jorgectf changed the title Add dot.jssupport Add dot.js support Jun 29, 2023
@github-actions github-actions bot added the JS label Jun 29, 2023
@jorgectf jorgectf changed the title Add dot.js support JS: [WIP] Add dot.js support Jun 29, 2023
@calumgrant calumgrant requested a review from asgerf July 3, 2023 08:35
@asgerf
Copy link
Contributor

asgerf commented Jul 3, 2023

Looks reasonable, but I'm thinking there are probably a few other types of .dot files that aren't part of this templating system, such as Graphviz dot. We'll need to make sure that it has no adverse effects when the repository contains such files. I don't think I'll have the time to investigate this week, however, so apologies in advance for leaving this PR hanging for a bit, as another issue is currently taking priority.

Copy link
Contributor

@asgerf asgerf left a comment

Choose a reason for hiding this comment

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

A quick code search shows about 800k files with the .dot extension, and from a few other searches I'd estimate around 1k of those are DoT templates.

Based on that, I'd like to restrict the extraction a bit to avoid extracting so many unrelated files as HTML.

For .erb files we only actually extract .html.erb files (due to this code). Would a similar restriction work for your use case, i.e. restricting to just .html.dot files?

Otherwise we can sniff the file header for HTML tags but that's a bit more work.


/**
* doT-style syntax, using `{{! }}` for safe interpolation, and `{{= }}` for
* unsafe interpolation.
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the two escaping mechanisms were flipped around, either in the comment or in the implementation.

  • The comment says {{! }} is safe, but the implementation treats it as raw (i.e. unsafe)
  • The comment says {{= }} is unsafe, but the implementation treats it as escaping (i.e. safe, in most contexts).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, sorry, the model is right, {{! }} is for unsafe (raw) interpolation.

@jorgectf
Copy link
Contributor Author

jorgectf commented Jul 7, 2023

Based on that, I'd like to restrict the extraction a bit to avoid extracting so many unrelated files as HTML.

For .erb files we only actually extract .html.erb files (due to this code). Would a similar restriction work for your use case, i.e. restricting to just .html.dot files?

Otherwise we can sniff the file header for HTML tags but that's a bit more work.

Thanks for the analysis! I'm happy to restrict it to .html.dot to avoid extracting unrelated files. wdyt @Kwstubbs?

@asgerf
Copy link
Contributor

asgerf commented Aug 1, 2023

@jorgectf any updates? Let me know if you need to help from my end. I'd prefer to get the PR merged rather than hanging.

@Kwstubbs
Copy link
Contributor

Kwstubbs commented Aug 1, 2023

@asgerf Hi Asger, Jorge is currently on a month long vacation. I will look into this PR very soon.

@Kwstubbs
Copy link
Contributor

Kwstubbs commented Aug 3, 2023

@asgerf What do you think about adding the .jst extension as well? Seems this is used by other template engines as well.

@asgerf
Copy link
Contributor

asgerf commented Aug 3, 2023

@Kwstubbs I'd prefer to focus on getting the PR merged, without expanding its scope. JST can be added in a separate PR.

@Kwstubbs
Copy link
Contributor

Kwstubbs commented Aug 4, 2023

@asgerf made the same changes as the .html.erb files, let me know if that will do the trick.

@asgerf
Copy link
Contributor

asgerf commented Aug 4, 2023

Unfortunately the test doesn't seem to react to the changes. There should be an update to the corresponding .expected file showing the new data flow into the template, and currently it doesn't find that flow.

I've pushed two commits that fix two of the underlying issues. For some reason the test still isn't finding the flow, so there's still some work to do here, though I need to commit my time elsewhere right now.

@jorgectf
Copy link
Contributor Author

Thank you @asgerf for your dedication, I'll work with @Kwstubbs to try to figure things out.

@asgerf
Copy link
Contributor

asgerf commented Aug 30, 2023

The issue might be that TEMPLATE_EXPR_OPENING_TAG needs to include {{! as the opening of an expression tag.

@sidshank sidshank added the awaiting-response The CodeQL team is awaiting further input or clarification from the original reporter of this issue. label Oct 10, 2023
@jorgectf
Copy link
Contributor Author

jorgectf commented Nov 6, 2023

The issue might be that TEMPLATE_EXPR_OPENING_TAG needs to include {{! as the opening of an expression tag.

The tests still don't find the new results :/

@erik-krogh
Copy link
Contributor

erik-krogh commented Nov 9, 2023

The tests still don't find the new results :/

I found the reason. I've pinged you in an internal PR.
There is also a backref to the internal PR.

Your tests work after that PR has been merged.

Also, could you add .html.dot to this list:

* FileType#HTML} (currently ".htm", ".html", ".xhtm", ".xhtml", ".vue", ".html.erb", ".jsp").

Edit: The internal PR has been merged.
If you do a merge with main, and build your CodeQL CLI from the latest main (including the above PR), then everything should work.
Alternatively you can wait for the next CodeQL CLI release.

@erik-krogh
Copy link
Contributor

Looks good, can you add a change-note?

@jorgectf jorgectf changed the title JS: [WIP] Add dot.js support JS: Add dot.js support Dec 18, 2023
@erik-krogh
Copy link
Contributor

erik-krogh commented Dec 19, 2023

Hmm.
The javascript/ql/test/library-tests/frameworks/Templating/Xss.qlref and javascript/ql/test/library-tests/frameworks/Templating/test.ql tests are failing in the CI.
Can you look into that?

I did some evaluations. They look fine and were very uneventful.

@jorgectf
Copy link
Contributor Author

Hmm. The javascript/ql/test/library-tests/frameworks/Templating/Xss.qlref and javascript/ql/test/library-tests/frameworks/Templating/test.ql tests are failing in the CI. Can you look into that?

I did some evaluations. They look fine and were very uneventful.

I haven't been able to figure out a fix for the error. I think it has to be with the internal test, which I'm not familiar with.

@erik-krogh
Copy link
Contributor

I haven't been able to figure out a fix for the error. I think it has to be with the internal test, which I'm not familiar with.

It's because you have to compile the extractor with your changes to see the changes to the tests.
I've done that and pushed the updated test outputs here.

I think those outputs are what we should expect from your changes?

@jorgectf
Copy link
Contributor Author

I haven't been able to figure out a fix for the error. I think it has to be with the internal test, which I'm not familiar with.

It's because you have to compile the extractor with your changes to see the changes to the tests. I've done that and pushed the updated test outputs here.

I think those outputs are what we should expect from your changes?

Yes, the expected results LGTM, thank you!

@erik-krogh erik-krogh removed the awaiting-response The CodeQL team is awaiting further input or clarification from the original reporter of this issue. label Jan 11, 2024
Copy link
Contributor

@erik-krogh erik-krogh left a comment

Choose a reason for hiding this comment

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

Great.
LGTM 👍

@asgerf: Do you have any comments?

@asgerf
Copy link
Contributor

asgerf commented Jan 11, 2024

Perhaps a final evaluation, otherwise LGTM, and thanks for driving this to completion!

@erik-krogh
Copy link
Contributor

Perhaps a final evaluation, otherwise LGTM, and thanks for driving this to completion!

Final evaluations (see backrefs) were very uneventful.
They were on nightly and default, and with building the extractor from github/codeql.

I'm merging.

@erik-krogh erik-krogh merged commit d782bd9 into github:main Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants