Presumably these aren't strangers in that sense
Checking the candy (even if just putting on a cursory show) is probably sufficient to drive the point home that this isn't an adult luring you with candy. It worked for me, although in my day there were more homemade goodies handed out but we knew the neighbors better. Still, there was a lot of scare over razor blades in apples and all that so there were the warnings to check items.
AFAIC, kids should canvas their neighborhoods or not at all. It is highly unlikely someone bent on harming children would choose a scenario where they are more likely to get caught.