Credit risk factors into the discount rate and price.
Consider an investment-grade bond and a junk bond that have the same maturity and coupon.
Junk bond yield = benchmark + credit spread > Investment-grade yield
Holding the coupon and time to maturity constant for both bonds, the junk bond with the higher yield and lower price to compensate for credit risk will have a lower duration.
This doesn't hold if the junk bond is trading at a discount and the investment-grade bond is at par or a premium, which is more than possible.
A bond at a discount has a duration ≥ duration of a premium bond. As time to maturity of both discount and premium bonds approach infinity, both durations converge as they approach the duration of a consol bond.