[15815] 2020-09-05_手把手教你自定义实现一个npmaudit

文档创建者:s7ckTeam
浏览次数:5
最后更新:2025-01-18
2020-09-05_手把手教你自定义实现一个npmaudit n p m   a u d i t n i g h t m a r e l e e   F r e e B u f   2 0 2 0 - 0 9 - 0 5 h t t p s : / / g i t h u b . c o m / b l a c k a r b i t e r / n o d e - d e p - a u d i t n p m h t t p s : / / w w w . n p m j s . c o m / p a c k a g e / n o d e - d e p - a u d i t 1 . n p m   a u d i t S e c u r i t y   a d v i s o r i e s S A S T n p m   a u d i t 使 n p m   a u d i t 2 . n p m   a u d i t p a c k a g e . j s o n p a c k a g e - l o c k . j s o n 2 . 1   n p m   a u d i t 使 S e c u r i t y   a d v i s o r i e s d h e a d e r x - s p i f e r a c k :   1 c o n s t   r u n   =   ( )   = > {     c o n s t   a u d i t C o m m a n d   =   ' n p m   a u d i t   - - r e g i s t r y = h t t p s : / / r . c n p m j s . o r g /   - - a u d i t - l e v e l = h i g h   - - p r o d u c t i o n   - - j s o n ' ;     c o n s t   e x e c O p t i o n s   =   {   m a x B u f f e r :   1 0   *   1 0 2 4   *   1 0 2 4   } ;     e x e c ( a u d i t C o m m a n d ,   e x e c O p t i o n s ,   f u n c t i o n   ( e r r o r ,   s t d o u t ,   s t d e r r )   {             i f   ( e r r o r   ! = =   n u l l )   {             c o n s o l e . l o g ( ' e x e c   e r r o r :   '   +   e r r o r ) ;                 r e t u r n ;             }             i f   ( s t d o u t )   {                 c o n s o l e . l o g ( s t d o u t ) ;             }     } ) ; } e x e c   e r r o r :   E r r o r :   C o m m a n d   f a i l e d :   n p m   a u d i t   - - r e g i s t r y = h t t p s : / / r . c n p m j s . o r g /   - - a u d i t - l e v e l = h i g h   - - p r o d u c t i o n   - - j s o n c o n s t   r e s u l t   =   a w a i t   a x i o s . g e t ( b a s e _ u r l   +   ' ? p a g e = '   +   p a g e N u m . t o S t r i n g ( )   +   ' & p e r P a g e = '   +   p e r P a g e N u m . t o S t r i n g ( ) ,             {                 h e a d e r s :   {                         ' x - r e q u e s t e d - w i t h ' :   ' X M L H t t p R e q u e s t ' ,
2 . 2   p a c k a g e . j s o n p a c k a g e . j s o n j s o n J S O N . p a r s e ( ) j s o n d e p e n d e n c i e s d e v D e p e n d e n c i e s 2 . 3   p a c k a g e - l o c k . j s o n p a c k a g e - l o c k . j s o n 便                         ' x - r e q u e s t e d - w i t h ' :   ' X M L H t t p R e q u e s t ' ,                         ' x - s p i f e r a c k ' :   ' 1 ' ,                 } ,             } ) ;             c o n s t   d a t a _ j s o n   =   r e s u l t . d a t a ;             t o t a l _ n u m   =   d a t a _ j s o n . a d v i s o r i e s D a t a . t o t a l ;             c o n s t   o b j e c t s   =   d a t a _ j s o n . a d v i s o r i e s D a t a . o b j e c t s ; f u n c t i o n   D e n p e n d e n c y N o d e ( n a m e ,   v e r s i o n ,   v u l I n d e x = - 1 ,   i s D e v = f a l s e )   { / /   便     t h i s . i d e n t i f y   =   g e t M d 5 ( M a t h . r a n d o m ( ) . t o S t r i n g ( ) ) ; / /         t h i s . d e e p   =   0 ; / /       t h i s . n a m e   =   n a m e ; / /       t h i s . v e r s i o n   =   v e r s i o n ; / /   2 . 1 便     t h i s . v u l I n d e x   =   v u l I n d e x ; / /       t h i s . i s D e v   =   i s D e v ; / /       t h i s . p a r e n t   =   n u l l ; / /       t h i s . c h i l d r e n   =   [ ] ; } / /   f u n c t i o n   D e n p e n d e n c y T r e e ( n a m e ,   v e r s i o n )   {     l e t   d e n p e n d e n c y N o d e   =   n e w   D e n p e n d e n c y N o d e ( n a m e ,   v e r s i o n ) ;     t h i s . _ r o o t   =   d e n p e n d e n c y N o d e ; } / /   c a l l b a c k D e n p e n d e n c y T r e e . p r o t o t y p e . t r a v e r s e D F   =   f u n c t i o n   ( c a l l b a c k )   {     ( f u n c t i o n   r e c u r s e ( c u r r e n t N o d e )   {         f o r   ( l e t   i   =   0 ,   {   l e n g t h   }   =   c u r r e n t N o d e . c h i l d r e n ;   i   <   l e n g t h ;   i + + )   {             r e c u r s e ( c u r r e n t N o d e . c h i l d r e n [ i ] ) ;         }         c a l l b a c k ( c u r r e n t N o d e ) ;     } ) ( t h i s . _ r o o t ) ; } ; / /   D e n p e n d e n c y T r e e . p r o t o t y p e . c o n t a i n s   =   f u n c t i o n   ( c a l l b a c k ,   t r a v e r s a l )   {     t r a v e r s a l . c a l l ( t h i s ,   c a l l b a c k ) ; } ; / /   i d e n t i f y D e n p e n d e n c y T r e e . p r o t o t y p e . a d d   =   f u n c t i o n   ( n a m e ,   v e r s i o n ,   v u l I n d e x ,   i s D e v ,   t o I d e n t i f y ,   t r a v e r s a l )   {     l e t   c h i l d   =   n e w   D e n p e n d e n c y N o d e ( n a m e ,   v e r s i o n ,   v u l I n d e x ,   i s D e v ) ;     l e t   p a r e n t   =   n u l l ;     l e t   c a l l b a c k   =   f u n c t i o n   ( n o d e )   {         i f   ( n o d e . i d e n t i f y   = = =   t o I d e n t i f y )   {             p a r e n t   =   n o d e ;         }
3 2 . 4   t r a v e r s e D F c a l l b a c k v u l I n d e x   - 1   2 . 5       } ;     t h i s . c o n t a i n s ( c a l l b a c k ,   t r a v e r s a l ) ;     i f   ( p a r e n t )   {         p a r e n t . c h i l d r e n . p u s h ( c h i l d ) ;         c h i l d . p a r e n t   =   p a r e n t ;         c h i l d . d e e p   =   p a r e n t . d e e p   +   1 ;     }   e l s e   {         t h r o w   n e w   E r r o r ( ' C a n n o t   a d d   n o d e   t o   a   n o n - e x i s t e n t   p a r e n t . ' ) ;     }     r e t u r n   [ c h i l d . i d e n t i f y ,   c h i l d . d e e p ] ; } ; d e C o n s t r u c t D e n p e n d e n c y T r e e ( r e s u l t s )   { / /           c o n s t   d e p e n d e n c y _ l i s t s   =   [ ] ;         c o n s t   d e n p e n d e n c y T r e e   =   r e s u l t s [ ' d e n p e n d e n c y T r e e ' ] ;         d e n p e n d e n c y T r e e . t r a v e r s e D F ( n o d e   = >   {             i f   ( n o d e . v u l I n d e x   >   - 1 )   {                 l e t   _ l i s t   =   [ ] ;                 w h i l e ( n o d e . p a r e n t )   {                     _ l i s t . p u s h ( n o d e ) ;                     n o d e   =   n o d e . p a r e n t ;                 }                 d e p e n d e n c y _ l i s t s . p u s h ( _ l i s t ) ;             }         } ) ;         r e s u l t s [ ' d e p e n d e n c y L i s t s ' ]   =   d e p e n d e n c y _ l i s t s ;     } c o n s t   v u l n e r a b l e _ v e r s i o n   =   ' > = 0 . 2 . 1   < 1 . 0 . 0   | |   > = 1 . 2 . 3 ' ; c o n s o l e . l o g ( i n n e r J u d g e ( ' 0 . 0 . 8 ' ,   v u l n e r a b l e _ v e r s i o n ) ) ; f u n c t i o n   i n n e r J u d g e ( p k V e r s i o n ,   v u l n e r a b l e _ v e r s i o n )   {     c o n s t   v _ l i s t s   =   v u l n e r a b l e _ v e r s i o n . s p l i t ( ' | | ' ) . m a p ( ( k e y )   = >   {         c o n s t   i i _ l i s t   =   k e y . t r i m ( ) . s p l i t ( '   ' ) . m a p ( ( k e y )   = >   {             r e t u r n   k e y . t r i m ( ) ;         } ) ;         r e t u r n   i i _ l i s t ;     } ) ;     l e t   f i n a l _ i s _ v u l   =   f a l s e ;     c o n s t   s i n g l e _ s y m b o l   =   [ ' > ' ,   ' > = ' ,   ' < ' ,   ' < = ' ,   ' ~ ' ] ;     f o r   ( c o n s t   v _ l i s t   o f   v _ l i s t s )   {         l e t   j u d e g e _ l i s t   =   [ ] ;         l e t   l a s t _ i n d e x   =   0 ;
        f o r   ( l e t   i = 0 ;   i < v _ l i s t . l e n g t h ;   i + + )   {             c o n s t   _ i t e m   =   v _ l i s t [ i ] ;             i f   ( ( _ i t e m   ! =   ' * ' )   & &   ( s i n g l e _ s y m b o l . i n d e x O f ( _ i t e m . s u b s t r i n g ( 0 ,   2 ) )   = =   - 1 )   & &                                                           ( s i n g l e _ s y m b o l . i n d e x O f ( _ i t e m . s u b s t r i n g ( 0 ,   1 ) )   = =   - 1 )   & &                                                         ( _ i t e m . t r i m ( )   ! =   ' ' ) )   {                 l e t   _ s s t   =   ' ' ;                 f o r   ( l e t   j = l a s t _ i n d e x ;   j < = i ;   j + + )   {                     _ s s t   =   ` $ { _ s s t . t r i m ( ) } $ { v _ l i s t [ j ] . t r i m ( ) } ` ;                 }                 j u d e g e _ l i s t . p u s h ( _ s s t ) ;                 l a s t _ i n d e x   =   i   +   1 ;             }   e l s e   i f   ( s i n g l e _ s y m b o l . i n d e x O f ( _ i t e m )   = =   - 1   & &   _ i t e m . t r i m ( )   ! =   ' ' )   {                 j u d e g e _ l i s t . p u s h ( _ i t e m ) ;             }   e l s e   i f   ( _ i t e m   = =   ' * '   & &   _ i t e m . t r i m ( )   ! =   ' ' )   {                 j u d e g e _ l i s t . p u s h ( _ i t e m ) ;             }         }         i f   ( j u d e g e _ l i s t . l e n g t h   = =   0 )   {             j u d e g e _ l i s t   =   v _ l i s t ;         }         / /   c o n s o l e . l o g ( v _ l i s t ) ;         / /   c o n s o l e . l o g ( j u d e g e _ l i s t ) ;         / /   c o n s o l e . l o g ( ' - - - - - - - - - - - - ' ) ;         l e t   i s _ v u l   =   f a l s e ;         s w i t c h   ( j u d e g e _ l i s t . l e n g t h )   {             c a s e   1 :                 i s _ v u l   =   s i n g l e J u d g e ( p k V e r s i o n ,   j u d e g e _ l i s t [ 0 ] ) ;                 b r e a k ;             c a s e   2 :                 i s _ v u l   =   s i n g l e J u d g e ( p k V e r s i o n ,   j u d e g e _ l i s t [ 0 ] )   & &   s i n g l e J u d g e ( p k V e r s i o n ,   j u d e g e _ l i s t [ 1 ] ) ;                 b r e a k ;             d e f a u l t :                 c o n s o l e . l o g ( ' I m p o s s i b l e   a r r a y   l e n g t h . ' ,   j u d e g e _ l i s t ) ;                 b r e a k ;         }         i f   ( i s _ v u l )   {             f i n a l _ i s _ v u l   =   i s _ v u l ;             b r e a k ;         }     }     r e t u r n   f i n a l _ i s _ v u l ; } f u n c t i o n   s i n g l e J u d g e ( p k V e r s i o n ,   _ v )   {     l e t   i s _ v u l   =   f a l s e ;     i f   ( _ v   = =   ' * ' )   {         i s _ v u l   =   t r u e ;     }   e l s e   i f   ( _ v . i n d e x O f ( ' ~ ' )   = =   0 )   {         i f   ( p k V e r s i o n . i n d e x O f ( _ v . s u b s t r i n g ( 1 ) )   = =   0 )   {             i s _ v u l   =   t r u e ;         }     }   e l s e   i f   ( _ v . i n d e x O f ( ' < = ' )   = =   0 )   {         i f   ( p k V e r s i o n   < =   _ v . s u b s t r i n g ( 2 ) )   {             i s _ v u l   =   t r u e ;         }
3 .     }   e l s e   i f   ( _ v . i n d e x O f ( ' < ' )   = =   0 )   {         i f   ( p k V e r s i o n   <   _ v . s u b s t r i n g ( 1 ) )   {             i s _ v u l   =   t r u e ;         }     }   e l s e   i f   ( _ v . i n d e x O f ( ' > = ' )   = =   0 )   {         i f   ( p k V e r s i o n   > =   _ v . s u b s t r i n g ( 2 ) )   {             i s _ v u l   =   t r u e ;         }     }   e l s e   i f   ( _ v . i n d e x O f ( ' > ' )   = =   0 )   {         i f   ( p k V e r s i o n   >   _ v . s u b s t r i n g ( 1 ) )   {             i s _ v u l   =   t r u e ;         }     }     r e t u r n   i s _ v u l ; } S t a r t   p u l l   s e c u r i t y   a d v i s o r i e s . D a t a   p u l l   p r o g r e s s :   6 . 9 9 7 % D a t a   p u l l   p r o g r e s s :   1 3 . 9 9 % D a t a   p u l l   p r o g r e s s :   2 0 . 9 9 % D a t a   p u l l   p r o g r e s s :   2 7 . 9 9 % D a t a   p u l l   p r o g r e s s :   3 4 . 9 8 % D a t a   p u l l   p r o g r e s s :   4 1 . 9 8 % D a t a   p u l l   p r o g r e s s :   4 8 . 9 8 % D a t a   p u l l   p r o g r e s s :   5 5 . 9 8 % D a t a   p u l l   p r o g r e s s :   6 2 . 9 8 % D a t a   p u l l   p r o g r e s s :   6 9 . 9 7 % D a t a   p u l l   p r o g r e s s :   7 6 . 9 7 % D a t a   p u l l   p r o g r e s s :   8 3 . 9 7 % D a t a   p u l l   p r o g r e s s :   9 0 . 9 7 % D a t a   p u l l   p r o g r e s s :   9 7 . 9 7 % D a t a   p u l l   p r o g r e s s :   1 0 0 % E n d .   S e c u r i t y   a d v i s o r i e s   s i z e   1 4 2 9 .   C o n s u m e   t i m e :   1 8 . 7 3 4 s . S t a r t   g e t   b a s e   d e p e n d e n c i e s   b y   p a c k a g e . j s o n .   F i l e   p a t h :   / p a t h / t o / p a c k a g e . j s o n E n d .   C o n s u m e   t i m e :   1 8 . 8 7 9 s . S t a r t   c o n s t r u c t   d e p e n d e n c y   t r e e   b y   p a c k a g e - l o c k . j s o n .   L o c k   f i l e   p a t h :   / p a t h / t o / p a c k a g e - l o c k . j s o n M a x   d e p e n d e n c y   d e e p   i s   3 E n d .   C o n s u m e   t i m e :   0 . 9 0 2 9 9 9 9 9 9 9 9 9 9 9 8 7 s . S t a r t   g e n e r a t e   d e p e n d e n c y   l i s t s . E n d .   G e n e r a t e   2 2 3   d e p e n d e n c y   l i s t .   C o n s u m e   t i m e   0 s                 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -                 R e s u l t   S i z e             :   2 2 3                 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -                 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -                 S e v e r i t y                   :   l o w                 P a c k a g e                     :   m i n i m i s t                 V e r s i o n                     :   0 . 0 . 8                 V u l n e r a b l e V e r s i o n :   < 0 . 2 . 1   | |   > = 1 . 0 . 0   < 1 . 2 . 3                 P a t c h e d V s e r s i o n     :   > = 0 . 2 . 1   < 1 . 0 . 0   | |   > = 1 . 2 . 3                 D e p e n d e n c y P a t h       :   m k d i r p   >   m i n i m i s t                 D e v                             :   f a l s e
4 . n p m   a u d i t                 D e v                             :   f a l s e                 M o r e I n f o                   :   h t t p s : / / w w w . n p m j s . c o m / a d v i s o r i e s / 1 1 7 9                 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - . . . . . . .

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则