@@ -203,6 +203,12 @@ public class Functions {
203203 private static final AtomicLong iota = new AtomicLong ();
204204 private static Logger LOGGER = Logger .getLogger (Functions .class .getName ());
205205
206+ /**
207+ * Escape hatch to use the non-recursive f:password masking.
208+ */
209+ private static /* non-final */ boolean NON_RECURSIVE_PASSWORD_MASKING_PERMISSION_CHECK = SystemProperties .getBoolean (Functions .class .getName () + ".nonRecursivePasswordMaskingPermissionCheck" );
210+
211+
206212 public Functions () {
207213 }
208214
@@ -2252,13 +2258,38 @@ public String getPasswordValue(Object o) {
22522258 StaplerRequest2 req = Stapler .getCurrentRequest2 ();
22532259 if (o instanceof Secret || Secret .BLANK_NONSECRET_PASSWORD_FIELDS_WITHOUT_ITEM_CONFIGURE ) {
22542260 if (req != null ) {
2255- Item item = req .findAncestorObject (Item .class );
2256- if (item != null && !item .hasPermission (Item .CONFIGURE )) {
2257- return "********" ;
2258- }
2259- Computer computer = req .findAncestorObject (Computer .class );
2260- if (computer != null && !computer .hasPermission (Computer .CONFIGURE )) {
2261- return "********" ;
2261+ if (NON_RECURSIVE_PASSWORD_MASKING_PERMISSION_CHECK ) {
2262+ Item item = req .findAncestorObject (Item .class );
2263+ if (item != null && !item .hasPermission (Item .CONFIGURE )) {
2264+ return "********" ;
2265+ }
2266+ Computer computer = req .findAncestorObject (Computer .class );
2267+ if (computer != null && !computer .hasPermission (Computer .CONFIGURE )) {
2268+ return "********" ;
2269+ }
2270+ } else {
2271+ List <Ancestor > ancestors = req .getAncestors ();
2272+ for (Ancestor ancestor : Iterators .reverse (ancestors )) {
2273+ Object type = ancestor .getObject ();
2274+ if (type instanceof Item item ) {
2275+ if (!item .hasPermission (Item .CONFIGURE )) {
2276+ return "********" ;
2277+ }
2278+ break ;
2279+ }
2280+ if (type instanceof Computer computer ) {
2281+ if (!computer .hasPermission (Computer .CONFIGURE )) {
2282+ return "********" ;
2283+ }
2284+ break ;
2285+ }
2286+ if (type instanceof View view ) {
2287+ if (!view .hasPermission (View .CONFIGURE )) {
2288+ return "********" ;
2289+ }
2290+ break ;
2291+ }
2292+ }
22622293 }
22632294 }
22642295 }
0 commit comments