Skip to content

JS: Actually extract .html.erb files. #12190

Merged
erik-krogh merged 5 commits into
github:mainfrom
erik-krogh:fix-erb
Feb 28, 2023
Merged

JS: Actually extract .html.erb files. #12190
erik-krogh merged 5 commits into
github:mainfrom
erik-krogh:fix-erb

Conversation

@erik-krogh
Copy link
Copy Markdown
Contributor

@erik-krogh erik-krogh commented Feb 14, 2023

CVE-2022-3704: TP

The file-extension check only works on the last part of the extension, so I had to change my implementation.
We already have a filter for which files to extract, so I just put .erb as an extension we support, but then use the filter to ensure it's only .html.erb files that are considered.

I didn't test the previous PR for this well enough.

Evaluation on nightly was very unevenful.
Evaluation on a bunch of rails projects was very eventful.
Lots of new results (in .html.erb files), slightly worse performance (from extracting more files).
But it looks good to me.

@erik-krogh erik-krogh added JS no-change-note-required This PR does not need a change note labels Feb 14, 2023
@erik-krogh erik-krogh marked this pull request as ready for review February 16, 2023 08:19
@erik-krogh erik-krogh requested a review from a team as a code owner February 16, 2023 08:19
/** Determine the {@link FileType} for a given file based on its extension only. */
public static FileType forFileExtension(File f) {
String lcExt = StringUtil.lc(FileUtil.extension(f));
String lcExt = StringUtil.lc(FileUtil.extension(f)); // TODO: Here, it doesn't recognize .html.erb files
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it helpful to keep this comment in? Unless you plan on changing something in the future, I'd suggest dropping TODO:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oops, I forgot to remove that 😅

}
// for ERB files we are only interrested in `.html.erb` files
if (FileUtil.extension(f).equalsIgnoreCase(".erb")) {
if (!f.getName().endsWith(".html.erb")) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You could simplify this with

if(f.getName().endsWith(".html.erb"))
  return true;

This code doesn't handle upper case - is this important?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Your suggestion wouldn't work, because it would let through all .erb files (the super.contains(f, lcExt, config); call returns true for any .erb file).

This code doesn't handle upper case - is this important?

I don't think so, but the existing code handles upper case, so I wanted to keep that.

I'll keep the code as is.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think handling upper case is important, but I feel we should test things consistently. Having equalsIgnoreCase in combination with a case sensitive endsWith feels wrong.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Agreed on the logic - didn't see that .erb would have been matched in the following lines.

You could just shove in f.getName().toLowerCase().endsWith(".html.erb")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Agree that we should do f.getName().toLowerCase() in the second branch - keeps it more obvious and also handles upper case extensions.

@calumgrant calumgrant requested a review from aibaars February 20, 2023 09:34
@erik-krogh erik-krogh requested a review from a team as a code owner February 27, 2023 16:19
@erik-krogh erik-krogh merged commit f3f5f6e into github:main Feb 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

JS no-change-note-required This PR does not need a change note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants