Skip to content

Conversation

diox
Copy link
Member

@diox diox commented Aug 12, 2025

Fixes mozilla/addons#15765
(Also addresses follow-ups for mozilla/addons#15763)

Description

Initial implementation of mozilla/addons#15763 already triggered a new scan when developer or add-on name changes outside of the XPI, but we didn't re-trigger the scanner actions. This does.

Context

To handle the case where a scanner action is run multiple times (something that is specific to NARC, doesn't happen for other scanners), the actions now check for a NeedsHumanReview corresponding to a scanner action before doing anything: if there weren't any scanner action NHR, or if one or more active scanner action NHR exist, we proceed with the action, but otherwise we abort (reviewer has acknowledged the NHR and the scanner shouldn't override what the reviewer has done)

Testing

Initial setup

  • Add a Scanner rule in the admin for the narc scanner with whatever regexp you want in the definition of the rule. Make the rule active and associate an action with it, for instance flag for human review.
  • Enable enable-narc waffle switch
  • Enable run-action-in-auto-approve waffle switch

API submission while providing a different name

  • Craft an add-on XPI that would not match the rule created above.
  • Submit that XPI as a new listed add-on with the add-on API while passing a name through the parameters that would match the rule above
  • Your rule action should be triggered on that add-on

Changing the name afterwards

  • Craft an add-on XPI that would not match the rule created above.
  • Submit that XPI
  • Change the add-on name with devhub or the API with a name that matches the rule above
  • Your rule action should be triggered on that add-on

Changing the name afterwards but the add-on was reviewed

  • Craft an add-on XPI that would match the rule created above.
  • Submit that XPI
  • Your rule action should be triggered on that add-on
  • As a reviewer, clear the NHR in some way, like approving/confirming auto-approval.
  • As the developer, change your display name to a name that matches the rule above (this doesn't re-trigger the rule yet, but will be taken into consideration when re-scanning in the next step)
  • As the developer, change the add-on name with devhub or the API to a different name that matches the rule above
  • Your rule action should not be triggered on that add-on (a reviewer approved the code already)

diox added 4 commits August 12, 2025 13:00
…n version

To handle the case where a scanner action is run multiple times, the actions
now check for a NeedsHumanReview corresponding to a scanner action before
doing anything: if there weren't any scanner action NHR, or if one or more
active scanner action NHR exist, we proceed with the action, but otherwise
we abort (reviewer has acknowledged the NHR and the scanner shouldn't
override what the reviewer has done)
@diox diox marked this pull request as ready for review August 12, 2025 12:49
@diox diox requested a review from eviljeff August 12, 2025 12:49
@eviljeff
Copy link
Member

re:

if there weren't any scanner action NHR, or if one or more active scanner action NHR exist, we proceed with the action, but otherwise we abort (reviewer has acknowledged the NHR and the scanner shouldn't override what the reviewer has done)

Do you mean "active"? (an active NHR would mean the reviewer hasn't looked at the addon/version; an inactive would mean they have)

@diox
Copy link
Member Author

diox commented Aug 13, 2025

Do you mean "active"? (an active NHR would mean the reviewer hasn't looked at the addon/version; an inactive would mean they have)

My sentence was poorly worded, the code is less confusing :) I meant:

  • If there are any NHR, apply the action as normal (including flagging)
  • If there are any active NHR, apply the action without flagging again
  • Otherwise (there are one or more NHR, but all inactive), skip the action entirely, as it means a reviewer already looked at it.

Comment on lines +25 to +36
if not version.needshumanreview_set.filter(
reason=NeedsHumanReview.REASONS.SCANNER_ACTION
).exists():
version.needshumanreview_set.create(
reason=NeedsHumanReview.REASONS.SCANNER_ACTION
)
return True
# If it has been flagged already... then return True only if one of the
# flags is active still.
return version.needshumanreview_set.filter(
reason=NeedsHumanReview.REASONS.SCANNER_ACTION, is_active=True
).exists()
Copy link
Member

Choose a reason for hiding this comment

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

Nit/optimization: This is logically correct, but we're running two database queries to check the NHRs exist - if we run a values or values_list of is_active (and group by is_active) we should be able to know in a single query if there any any active or inactive NHRs

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right, I don't think it matters enough to refactor it at this point though so I'm going to leave as-is for now.

scanner_result.results = [json.loads(result) for result in sorted(results)]
run_action = False
new_results = [json.loads(result) for result in sorted(results)]
if version and new_results != scanner_result.results:
Copy link
Member

Choose a reason for hiding this comment

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

The results don't contain any datetimes or other unique values, right?

Copy link
Member Author

@diox diox Aug 13, 2025

Choose a reason for hiding this comment

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

They shouldn't, it should all be stable. At some point in the original NARC implementation I had the trigger in there (with value being version or upload) and removed it when I realized it would prevent this comparison from working.

Comment on lines 292 to 295
if scanner_result.has_matches:
statsd.incr('devhub.narc.has_matches')
for scanner_rule in scanner_result.matched_rules.all():
statsd.incr(f'devhub.narc.rule.{scanner_rule.id}.match')
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we don't want to increase the statsd pings if the results haven't changed? (it'd be inflating the match counts)

Copy link
Member Author

Choose a reason for hiding this comment

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

I went back and forth on this and I'm still not sure so I kept it as-is. The problem is, if you want to compare the number of matches against the number of runs (devhub.narc.success) then you need to still increase the pings even if the results haven't changed.

I introduced devhub.narc.results_differ ping to at least monitor when results differ but maybe we'd want another to tell us when we ran the scanner on a version and results were the same...

Copy link
Member Author

Choose a reason for hiding this comment

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

Filed mozilla/addons#15776 as a follow-up.

@diox diox merged commit 81b89a8 into mozilla:master Aug 13, 2025
45 checks passed
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.

[Task]: Re-trigger name scanning on name change
2 participants