Skip to content

JavaScript: Model util.deprecate as a pre call-graph step.#3809

Merged
semmle-qlci merged 2 commits into
github:masterfrom
max-schaefer:util-deprecate
Jun 26, 2020
Merged

JavaScript: Model util.deprecate as a pre call-graph step.#3809
semmle-qlci merged 2 commits into
github:masterfrom
max-schaefer:util-deprecate

Conversation

@max-schaefer
Copy link
Copy Markdown
Contributor

The motivation for this is the flow-summaries work, where we would be able to infer a summary for an (old) npm package if it weren't for a pesky util.deprecate intervening. I have no evidence that it will move the needle on actual alerts, so I didn't include a change note, but I can certainly add one if desired.

@max-schaefer max-schaefer requested a review from a team June 25, 2020 16:57
}

export const exportedConnection = getConnection();
export const exportedConnection = require("util").deprecate(getConnection(), "don't use this");
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.

Hm, this test is a little misleading as the argument to deprecate should be a function - it just seems to return an empty object otherwise. And we currently don't type-track plain functions (my latest attempt didn't scale on gecko), so I'm not sure this change would have the intended effect.

So this probably wasn't the perfect use-case for PreCallGraphStep like I thought it was, but I still feel like it should be. I'm happy to merge like this if it works for flow-summaries, and I'll try and poke at the call graph builder again to make it work.

Could you add a test that actually passes a function to util.deprecate? (to show the FN)

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.

Ah, that was just me being lazy and trying to shoe-horn this onto an existing test instead of making a new one. Will fix.

It's a good point about util.deprecate discarding non-functions, though. That makes it a little suspect as a general-purpose data-flow step, though I can't immediately think of a scenario where it would cause false positives.

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.

Tests added; please take a look.

asgerf
asgerf previously approved these changes Jun 26, 2020
Copy link
Copy Markdown
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.

Thanks 👍

@max-schaefer
Copy link
Copy Markdown
Contributor Author

@asgerf, could I get a re-approval? I had to slightly adjust the regex in the test since Java (and hence QL) doesn't support quantifiers in lookbehinds. No idea why it initially worked on my machine; maybe different Java versions.

@semmle-qlci semmle-qlci merged commit b015c73 into github:master Jun 26, 2020
@max-schaefer max-schaefer deleted the util-deprecate branch July 2, 2020 08:42
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.

3 participants