I think there is a way to (potentially) achieve this with the depth
flag.
caveat 1: The official npm update documentation advices to use a depth of 9999 to recursively inspect all dependencies. But on my setup that either results in an error or npm freezing. So I use a realistic depth of 1 or 2. (0 is the default, meaning only direct dependencies)
UPDATE: See mike's comment below. The depth option is no longer supported; npm update <name>
will now update all instances of name
in the tree, except those in a bundled or shrinkwrapped tree.
So this should still work:
npm update vulnerable_package
caveat: This only works if there is an updated version available of the nested package (with a fix for the vulnerability) that still fits the version range of your dependency. So if this is your dependency tree:
Your Package -> Dependency@^1.0.0 -> Vulnerable_package@^2.1.0
And the vulnerability fix is in Vulnerable_package version 3.0.0, then it won't work, since npm update will only update to the highest version that still fits the version range of your dependency. (in this case the highest 2.x.x release)