784.index.js 240 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225
  1. exports.id = 784;
  2. exports.ids = [784];
  3. exports.modules = {
  4. /***/ 61452:
  5. /***/ ((module) => {
  6. function webpackEmptyContext(req) {
  7. var e = new Error("Cannot find module '" + req + "'");
  8. e.code = 'MODULE_NOT_FOUND';
  9. throw e;
  10. }
  11. webpackEmptyContext.keys = () => ([]);
  12. webpackEmptyContext.resolve = webpackEmptyContext;
  13. webpackEmptyContext.id = 61452;
  14. module.exports = webpackEmptyContext;
  15. /***/ }),
  16. /***/ 3196:
  17. /***/ ((module) => {
  18. function webpackEmptyContext(req) {
  19. var e = new Error("Cannot find module '" + req + "'");
  20. e.code = 'MODULE_NOT_FOUND';
  21. throw e;
  22. }
  23. webpackEmptyContext.keys = () => ([]);
  24. webpackEmptyContext.resolve = webpackEmptyContext;
  25. webpackEmptyContext.id = 3196;
  26. module.exports = webpackEmptyContext;
  27. /***/ }),
  28. /***/ 3708:
  29. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  30. "use strict";
  31. Object.defineProperty(exports, "__esModule", ({ value: true }));
  32. exports.validateTags = exports.generateTags = exports.generateProjectAttributes = exports.validateProjectAttributes = void 0;
  33. const chalk_1 = __webpack_require__(32589);
  34. const fs = __webpack_require__(35747);
  35. const Debug = __webpack_require__(15158);
  36. const pathUtil = __webpack_require__(85622);
  37. const cli_interface_1 = __webpack_require__(65266);
  38. const check_paths_1 = __webpack_require__(94501);
  39. const types_1 = __webpack_require__(94055);
  40. const config_1 = __webpack_require__(25425);
  41. const detect = __webpack_require__(45318);
  42. const spinner_1 = __webpack_require__(86766);
  43. const analytics = __webpack_require__(82744);
  44. const api_token_1 = __webpack_require__(95181);
  45. const print_deps_1 = __webpack_require__(79792);
  46. const monitor_1 = __webpack_require__(3959);
  47. const process_json_monitor_1 = __webpack_require__(21506);
  48. const snyk = __webpack_require__(9146); // TODO(kyegupov): fix import
  49. const formatters_1 = __webpack_require__(81329);
  50. const get_deps_from_plugin_1 = __webpack_require__(4842);
  51. const get_extra_project_count_1 = __webpack_require__(34355);
  52. const extract_package_manager_1 = __webpack_require__(22805);
  53. const convert_multi_plugin_res_to_multi_custom_1 = __webpack_require__(23110);
  54. const convert_single_splugin_res_to_multi_custom_1 = __webpack_require__(99695);
  55. const dev_count_analysis_1 = __webpack_require__(73898);
  56. const errors_1 = __webpack_require__(55191);
  57. const is_multi_project_scan_1 = __webpack_require__(62435);
  58. const ecosystems_1 = __webpack_require__(5168);
  59. const monitor_2 = __webpack_require__(62406);
  60. const process_command_args_1 = __webpack_require__(52369);
  61. const SEPARATOR = '\n-------------------------------------------------------\n';
  62. const debug = Debug('snyk');
  63. // This is used instead of `let x; try { x = await ... } catch { cleanup }` to avoid
  64. // declaring the type of x as possibly undefined.
  65. async function promiseOrCleanup(p, cleanup) {
  66. return p.catch((error) => {
  67. cleanup();
  68. throw error;
  69. });
  70. }
  71. // Returns an array of Registry responses (one per every sub-project scanned), a single response,
  72. // or an error message.
  73. async function monitor(...args0) {
  74. var _a;
  75. const { options, paths } = process_command_args_1.processCommandArgs(...args0);
  76. const results = [];
  77. if (options.id) {
  78. snyk.id = options.id;
  79. }
  80. if (options.allSubProjects && options['project-name']) {
  81. throw new Error('`--all-sub-projects` is currently not compatible with `--project-name`');
  82. }
  83. if (!options.docker) {
  84. check_paths_1.checkOSSPaths(paths, options);
  85. }
  86. if (options.docker && options['remote-repo-url']) {
  87. throw new Error('`--remote-repo-url` is not supported for container scans');
  88. }
  89. // TODO remove once https://github.com/snyk/cli/pull/3433 is merged
  90. if (options.docker && !options['app-vulns']) {
  91. options['exclude-app-vulns'] = true;
  92. }
  93. // Handles no image arg provided to the container command until
  94. // a validation interface is implemented in the docker plugin.
  95. if (options.docker && paths.length === 0) {
  96. throw new errors_1.MissingArgError();
  97. }
  98. api_token_1.apiOrOAuthTokenExists();
  99. let contributors = [];
  100. if (!options.docker && analytics.allowAnalytics()) {
  101. try {
  102. contributors = await dev_count_analysis_1.getContributors();
  103. }
  104. catch (err) {
  105. debug('error getting repo contributors', err);
  106. }
  107. }
  108. const ecosystem = ecosystems_1.getEcosystem(options);
  109. if (ecosystem) {
  110. const commandResult = await ecosystems_1.monitorEcosystem(ecosystem, paths, options, contributors);
  111. const [monitorResults, monitorErrors] = commandResult;
  112. return await monitor_2.getFormattedMonitorOutput(results, monitorResults, monitorErrors, options);
  113. }
  114. // Part 1: every argument is a scan target; process them sequentially
  115. for (const path of paths) {
  116. debug(`Processing ${path}...`);
  117. try {
  118. validateMonitorPath(path, options.docker);
  119. let analysisType = 'all';
  120. let packageManager;
  121. if (is_multi_project_scan_1.isMultiProjectScan(options)) {
  122. analysisType = 'all';
  123. }
  124. else if (options.docker) {
  125. analysisType = 'docker';
  126. }
  127. else {
  128. packageManager = detect.detectPackageManager(path, options);
  129. }
  130. const targetFile = !options.scanAllUnmanaged && options.docker && !options.file // snyk monitor --docker (without --file)
  131. ? undefined
  132. : options.file || detect.detectPackageFile(path);
  133. const displayPath = pathUtil.relative('.', pathUtil.join(path, targetFile || ''));
  134. const analyzingDepsSpinnerLabel = 'Analyzing ' +
  135. (packageManager ? packageManager : analysisType) +
  136. ' dependencies for ' +
  137. displayPath;
  138. await spinner_1.spinner(analyzingDepsSpinnerLabel);
  139. // Scan the project dependencies via a plugin
  140. debug('getDepsFromPlugin ...');
  141. // each plugin will be asked to scan once per path
  142. // some return single InspectResult & newer ones return Multi
  143. const inspectResult = await promiseOrCleanup(get_deps_from_plugin_1.getDepsFromPlugin(path, {
  144. ...options,
  145. path,
  146. packageManager,
  147. }), spinner_1.spinner.clear(analyzingDepsSpinnerLabel));
  148. analytics.add('pluginName', inspectResult.plugin.name);
  149. // We send results from "all-sub-projects" scanning as different Monitor objects
  150. // multi result will become default, so start migrating code to always work with it
  151. let perProjectResult;
  152. if (!cli_interface_1.legacyPlugin.isMultiResult(inspectResult)) {
  153. perProjectResult = convert_single_splugin_res_to_multi_custom_1.convertSingleResultToMultiCustom(inspectResult);
  154. }
  155. else {
  156. perProjectResult = convert_multi_plugin_res_to_multi_custom_1.convertMultiResultToMultiCustom(inspectResult);
  157. }
  158. const failedResults = inspectResult
  159. .failedResults;
  160. if (failedResults === null || failedResults === void 0 ? void 0 : failedResults.length) {
  161. failedResults.forEach((result) => {
  162. results.push({
  163. ok: false,
  164. data: new errors_1.MonitorError(500, result.errMessage),
  165. path: result.targetFile || '',
  166. });
  167. });
  168. }
  169. const postingMonitorSpinnerLabel = 'Posting monitor snapshot for ' + displayPath + ' ...';
  170. await spinner_1.spinner(postingMonitorSpinnerLabel);
  171. // Post the project dependencies to the Registry
  172. for (const projectDeps of perProjectResult.scannedProjects) {
  173. try {
  174. if (!projectDeps.depGraph && !projectDeps.depTree) {
  175. debug('scannedProject is missing depGraph or depTree, cannot run test/monitor');
  176. throw new errors_1.FailedToRunTestError('Your monitor request could not be completed. Please email support@snyk.io');
  177. }
  178. const extractedPackageManager = extract_package_manager_1.extractPackageManager(projectDeps, perProjectResult, options);
  179. analytics.add('packageManager', extractedPackageManager);
  180. const projectName = getProjectName(projectDeps);
  181. if (projectDeps.depGraph) {
  182. debug(`Processing ${(_a = projectDeps.depGraph.rootPkg) === null || _a === void 0 ? void 0 : _a.name}...`);
  183. print_deps_1.maybePrintDepGraph(options, projectDeps.depGraph);
  184. }
  185. if (projectDeps.depTree) {
  186. debug(`Processing ${projectDeps.depTree.name}...`);
  187. print_deps_1.maybePrintDepTree(options, projectDeps.depTree);
  188. }
  189. const tFile = projectDeps.targetFile || targetFile;
  190. const targetFileRelativePath = projectDeps.plugin.targetFile ||
  191. (tFile && pathUtil.join(pathUtil.resolve(path), tFile)) ||
  192. '';
  193. const res = await promiseOrCleanup(monitor_1.monitor(path, generateMonitorMeta(options, extractedPackageManager), projectDeps, options, projectDeps.plugin, targetFileRelativePath, contributors, generateProjectAttributes(options), generateTags(options)), spinner_1.spinner.clear(postingMonitorSpinnerLabel));
  194. res.path = path;
  195. const monOutput = formatters_1.formatMonitorOutput(extractedPackageManager, res, options, projectName, await get_extra_project_count_1.getExtraProjectCount(path, options, inspectResult));
  196. // push a good result
  197. results.push({ ok: true, data: monOutput, path, projectName });
  198. }
  199. catch (err) {
  200. // pushing this error allow this inner loop to keep scanning the projects
  201. // even if 1 in 100 fails
  202. results.push({ ok: false, data: err, path });
  203. }
  204. }
  205. }
  206. catch (err) {
  207. // push this error, the loop continues
  208. results.push({ ok: false, data: err, path });
  209. }
  210. finally {
  211. spinner_1.spinner.clearAll();
  212. }
  213. }
  214. // Part 2: process the output from the Registry
  215. if (options.json) {
  216. return process_json_monitor_1.processJsonMonitorResponse(results);
  217. }
  218. const output = results
  219. .map((res) => {
  220. if (res.ok) {
  221. return res.data;
  222. }
  223. const errorMessage = res.data && res.data.userMessage
  224. ? chalk_1.default.bold.red(res.data.userMessage)
  225. : res.data
  226. ? res.data.message
  227. : 'Unknown error occurred.';
  228. return (chalk_1.default.bold.white('\nMonitoring ' + res.path + '...\n\n') + errorMessage);
  229. })
  230. .join('\n' + SEPARATOR);
  231. if (results.every((res) => res.ok)) {
  232. return output;
  233. }
  234. throw new Error(output);
  235. }
  236. exports.default = monitor;
  237. function generateMonitorMeta(options, packageManager) {
  238. return {
  239. method: 'cli',
  240. packageManager,
  241. 'policy-path': options['policy-path'],
  242. 'project-name': options['project-name'] || config_1.default.PROJECT_NAME,
  243. isDocker: !!options.docker,
  244. prune: !!options.pruneRepeatedSubdependencies,
  245. 'remote-repo-url': options['remote-repo-url'],
  246. targetReference: options['target-reference'],
  247. };
  248. }
  249. /**
  250. * Parse an attribute from the CLI into the relevant enum type.
  251. *
  252. * @param attribute The project attribute (e.g. environment)
  253. * @param permitted Permitted options
  254. * @param options CLI options provided
  255. * @returns An array of attributes to set on the project or undefined to mean "do not touch".
  256. */
  257. function getProjectAttribute(attribute, permitted, options) {
  258. const permittedValues = Object.values(permitted);
  259. if (options[attribute] === undefined) {
  260. return undefined;
  261. }
  262. // Explicit flag to clear the existing values for this attribute already set on the project
  263. // e.g. if you specify --environment=
  264. // then this means you want to remove existing environment values on the project.
  265. if (options[attribute] === '') {
  266. return [];
  267. }
  268. // When it's specified without the =, we raise an explicit error to avoid
  269. // accidentally clearing the existing values.
  270. if (options[attribute] === true) {
  271. throw new errors_1.ValidationError(`--${attribute} must contain an '=' with a comma-separated list of values. To clear all existing values, pass no values i.e. --${attribute}=`);
  272. }
  273. const values = options[attribute].split(',');
  274. const extra = values.filter((value) => !permittedValues.includes(value));
  275. if (extra.length > 0) {
  276. throw new errors_1.ValidationError(`${extra.length} invalid ${attribute}: ${extra.join(', ')}. ` +
  277. `Possible values are: ${permittedValues.join(', ')}`);
  278. }
  279. return values;
  280. }
  281. function validateProjectAttributes(options) {
  282. // The validation is deep within the parsing, so call the generate but throw away the return for simplicity.
  283. // Using this method makes it much clearer what the intent is of the caller.
  284. generateProjectAttributes(options);
  285. }
  286. exports.validateProjectAttributes = validateProjectAttributes;
  287. function generateProjectAttributes(options) {
  288. return {
  289. criticality: getProjectAttribute('project-business-criticality', types_1.PROJECT_CRITICALITY, options),
  290. environment: getProjectAttribute('project-environment', types_1.PROJECT_ENVIRONMENT, options),
  291. lifecycle: getProjectAttribute('project-lifecycle', types_1.PROJECT_LIFECYCLE, options),
  292. };
  293. }
  294. exports.generateProjectAttributes = generateProjectAttributes;
  295. /**
  296. * Parse CLI --tags options into an internal data structure.
  297. *
  298. * If this returns undefined, it means "do not touch the existing tags on the project".
  299. *
  300. * Anything else means "replace existing tags on the project with this list" even if empty.
  301. *
  302. * @param options CLI options
  303. * @returns List of parsed tags or undefined if they are to be left untouched.
  304. */
  305. function generateTags(options) {
  306. if (options['project-tags'] === undefined && options['tags'] === undefined) {
  307. return undefined;
  308. }
  309. if (options['project-tags'] !== undefined && options['tags'] !== undefined) {
  310. throw new errors_1.ValidationError('Only one of --tags or --project-tags may be specified, not both');
  311. }
  312. const rawTags = options['tags'] === undefined ? options['project-tags'] : options['tags'];
  313. if (rawTags === '') {
  314. return [];
  315. }
  316. // When it's specified without the =, we raise an explicit error to avoid
  317. // accidentally clearing the existing tags;
  318. if (rawTags === true) {
  319. throw new errors_1.ValidationError(`--project-tags must contain an '=' with a comma-separated list of pairs (also separated with an '='). To clear all existing values, pass no values i.e. --project-tags=`);
  320. }
  321. const keyEqualsValuePairs = rawTags.split(',');
  322. const tags = [];
  323. for (const keyEqualsValue of keyEqualsValuePairs) {
  324. const parts = keyEqualsValue.split('=');
  325. if (parts.length !== 2) {
  326. throw new errors_1.ValidationError(`The tag "${keyEqualsValue}" does not have an "=" separating the key and value. For example: --project-tag=KEY=VALUE`);
  327. }
  328. tags.push({
  329. key: parts[0],
  330. value: parts[1],
  331. });
  332. }
  333. return tags;
  334. }
  335. exports.generateTags = generateTags;
  336. function validateTags(options) {
  337. // The validation is deep within the parsing, so call the generate but throw away the return for simplicity.
  338. // Using this method makes it much clearer what the intent is of the caller.
  339. generateTags(options);
  340. }
  341. exports.validateTags = validateTags;
  342. function validateMonitorPath(path, isDocker) {
  343. const exists = fs.existsSync(path);
  344. if (!exists && !isDocker) {
  345. throw new Error('"' + path + '" is not a valid path for "snyk monitor"');
  346. }
  347. }
  348. function getProjectName(projectDeps) {
  349. var _a, _b, _c, _d;
  350. return (((_a = projectDeps.meta) === null || _a === void 0 ? void 0 : _a.gradleProjectName) || ((_c = (_b = projectDeps.depGraph) === null || _b === void 0 ? void 0 : _b.rootPkg) === null || _c === void 0 ? void 0 : _c.name) || ((_d = projectDeps.depTree) === null || _d === void 0 ? void 0 : _d.name));
  351. }
  352. /***/ }),
  353. /***/ 21506:
  354. /***/ ((__unused_webpack_module, exports) => {
  355. "use strict";
  356. Object.defineProperty(exports, "__esModule", ({ value: true }));
  357. exports.processJsonMonitorResponse = void 0;
  358. function processJsonMonitorResponse(results) {
  359. let dataToSend = results.map((result) => {
  360. if (result.ok) {
  361. const jsonData = JSON.parse(result.data);
  362. if (result.projectName) {
  363. jsonData.projectName = result.projectName;
  364. }
  365. return jsonData;
  366. }
  367. return { ok: false, error: result.data.message, path: result.path };
  368. });
  369. // backwards compat - strip array if only one result
  370. dataToSend = dataToSend.length === 1 ? dataToSend[0] : dataToSend;
  371. const stringifiedData = JSON.stringify(dataToSend, null, 2);
  372. if (results.every((res) => res.ok)) {
  373. return stringifiedData;
  374. }
  375. const err = new Error(stringifiedData);
  376. err.json = stringifiedData;
  377. throw err;
  378. }
  379. exports.processJsonMonitorResponse = processJsonMonitorResponse;
  380. /***/ }),
  381. /***/ 52369:
  382. /***/ ((__unused_webpack_module, exports) => {
  383. "use strict";
  384. Object.defineProperty(exports, "__esModule", ({ value: true }));
  385. exports.processCommandArgs = void 0;
  386. function processCommandArgs(...args) {
  387. let options = {};
  388. if (typeof args[args.length - 1] === 'object') {
  389. options = args.pop();
  390. }
  391. args = args.filter(Boolean);
  392. // For repository scanning, populate with default path (cwd) if no path given
  393. if (args.length === 0 && !options.docker) {
  394. args.unshift(process.cwd());
  395. }
  396. return { options, paths: args };
  397. }
  398. exports.processCommandArgs = processCommandArgs;
  399. /***/ }),
  400. /***/ 55246:
  401. /***/ ((__unused_webpack_module, exports) => {
  402. "use strict";
  403. Object.defineProperty(exports, "__esModule", ({ value: true }));
  404. exports.TestCommandResult = exports.CommandResult = void 0;
  405. class CommandResult {
  406. constructor(result) {
  407. this.result = result;
  408. }
  409. toString() {
  410. return this.result;
  411. }
  412. getDisplayResults() {
  413. return this.result;
  414. }
  415. }
  416. exports.CommandResult = CommandResult;
  417. class TestCommandResult extends CommandResult {
  418. constructor() {
  419. super(...arguments);
  420. this.jsonResult = '';
  421. this.sarifResult = '';
  422. }
  423. getJsonResult() {
  424. return this.jsonResult;
  425. }
  426. getSarifResult() {
  427. return this.sarifResult;
  428. }
  429. static createHumanReadableTestCommandResult(humanReadableResult, jsonResult, sarifResult) {
  430. return new HumanReadableTestCommandResult(humanReadableResult, jsonResult, sarifResult);
  431. }
  432. static createJsonTestCommandResult(stdout, jsonResult, sarifResult) {
  433. return new JsonTestCommandResult(stdout, jsonResult, sarifResult);
  434. }
  435. }
  436. exports.TestCommandResult = TestCommandResult;
  437. class HumanReadableTestCommandResult extends TestCommandResult {
  438. constructor(humanReadableResult, jsonResult, sarifResult) {
  439. super(humanReadableResult);
  440. this.jsonResult = '';
  441. this.sarifResult = '';
  442. this.jsonResult = jsonResult;
  443. if (sarifResult) {
  444. this.sarifResult = sarifResult;
  445. }
  446. }
  447. getJsonResult() {
  448. return this.jsonResult;
  449. }
  450. getSarifResult() {
  451. return this.sarifResult;
  452. }
  453. }
  454. class JsonTestCommandResult extends TestCommandResult {
  455. constructor(stdout, jsonResult, sarifResult) {
  456. super(stdout);
  457. if (jsonResult) {
  458. this.jsonResult = jsonResult;
  459. }
  460. if (sarifResult) {
  461. this.sarifResult = sarifResult;
  462. }
  463. else {
  464. this.jsonResult = stdout;
  465. }
  466. }
  467. getJsonResult() {
  468. return this.jsonResult;
  469. }
  470. getSarifResult() {
  471. return this.sarifResult;
  472. }
  473. }
  474. /***/ }),
  475. /***/ 94501:
  476. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  477. "use strict";
  478. Object.defineProperty(exports, "__esModule", ({ value: true }));
  479. exports.checkOSSPaths = void 0;
  480. const errors_1 = __webpack_require__(55191);
  481. const detect_1 = __webpack_require__(45318);
  482. // Throw error if user specifies package file name as part of path,
  483. // and if user specifies multiple paths and used project-name option.
  484. function checkOSSPaths(paths, options) {
  485. let count = 0;
  486. for (const path of paths) {
  487. if (typeof path === 'string' && detect_1.isPathToPackageFile(path)) {
  488. throw errors_1.MissingTargetFileError(path);
  489. }
  490. else if (typeof path === 'string') {
  491. if (++count > 1 && options['project-name']) {
  492. throw new errors_1.UnsupportedOptionCombinationError([
  493. 'multiple paths',
  494. 'project-name',
  495. ]);
  496. }
  497. }
  498. }
  499. }
  500. exports.checkOSSPaths = checkOSSPaths;
  501. /***/ }),
  502. /***/ 55203:
  503. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  504. "use strict";
  505. Object.defineProperty(exports, "__esModule", ({ value: true }));
  506. exports.getBase64Encoding = exports.getCodeClientProxyUrl = void 0;
  507. const config_1 = __webpack_require__(25425);
  508. const user_config_1 = __webpack_require__(28137);
  509. function getCodeClientProxyUrl() {
  510. const url = new URL(config_1.default.API);
  511. const domain = url.origin;
  512. return (config_1.default.CODE_CLIENT_PROXY_URL ||
  513. domain.replace(/\/\/(ap[pi]\.)?/, '//deeproxy.'));
  514. }
  515. exports.getCodeClientProxyUrl = getCodeClientProxyUrl;
  516. function getBase64Encoding(enabled = user_config_1.config.get('use-base64-encoding')) {
  517. if (enabled) {
  518. return enabled.toLowerCase() === 'true';
  519. }
  520. return false;
  521. }
  522. exports.getBase64Encoding = getBase64Encoding;
  523. /***/ }),
  524. /***/ 65623:
  525. /***/ ((__unused_webpack_module, exports) => {
  526. "use strict";
  527. Object.defineProperty(exports, "__esModule", ({ value: true }));
  528. exports.CALL_PATH_TRAILING_ELEMENTS = exports.CALL_PATH_LEADING_ELEMENTS = exports.PATH_HIDDEN_ELEMENTS = exports.PATH_SEPARATOR = void 0;
  529. // Separator used while displaying various paths (e.g. package paths, call
  530. // paths) to the user
  531. exports.PATH_SEPARATOR = ' > ';
  532. // String used to signify hidden path elements e.g. for abbreviated paths
  533. exports.PATH_HIDDEN_ELEMENTS = '...';
  534. // Number of function names to show in the beginning of an abbreviated call path
  535. exports.CALL_PATH_LEADING_ELEMENTS = 2;
  536. // Number of function names to show in the end of an abbreviated call path
  537. exports.CALL_PATH_TRAILING_ELEMENTS = 2;
  538. /***/ }),
  539. /***/ 69813:
  540. /***/ ((__unused_webpack_module, exports) => {
  541. "use strict";
  542. Object.defineProperty(exports, "__esModule", ({ value: true }));
  543. exports.isUnmanagedEcosystem = void 0;
  544. function isUnmanagedEcosystem(ecosystem) {
  545. return ecosystem === 'cpp';
  546. }
  547. exports.isUnmanagedEcosystem = isUnmanagedEcosystem;
  548. /***/ }),
  549. /***/ 5168:
  550. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  551. "use strict";
  552. Object.defineProperty(exports, "__esModule", ({ value: true }));
  553. exports.getEcosystem = exports.getEcosystemForTest = void 0;
  554. var test_1 = __webpack_require__(60937);
  555. Object.defineProperty(exports, "testEcosystem", ({ enumerable: true, get: function () { return test_1.testEcosystem; } }));
  556. var monitor_1 = __webpack_require__(62406);
  557. Object.defineProperty(exports, "monitorEcosystem", ({ enumerable: true, get: function () { return monitor_1.monitorEcosystem; } }));
  558. var plugins_1 = __webpack_require__(78053);
  559. Object.defineProperty(exports, "getPlugin", ({ enumerable: true, get: function () { return plugins_1.getPlugin; } }));
  560. /**
  561. * Ecosystems are listed here if you opt in to the new plugin test flow.
  562. * This is a breaking change to the old plugin formats, so only a select few
  563. * plugins currently work with it.
  564. *
  565. * Currently container scanning is not yet ready to work with this flow,
  566. * hence this is in a separate function from getEcosystem().
  567. */
  568. function getEcosystemForTest(options) {
  569. if (options.unmanaged) {
  570. return 'cpp';
  571. }
  572. if (options.code) {
  573. return 'code';
  574. }
  575. return null;
  576. }
  577. exports.getEcosystemForTest = getEcosystemForTest;
  578. function getEcosystem(options) {
  579. if (options.unmanaged) {
  580. return 'cpp';
  581. }
  582. if (options.docker) {
  583. return 'docker';
  584. }
  585. return null;
  586. }
  587. exports.getEcosystem = getEcosystem;
  588. /***/ }),
  589. /***/ 62406:
  590. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  591. "use strict";
  592. Object.defineProperty(exports, "__esModule", ({ value: true }));
  593. exports.getFormattedMonitorOutput = exports.generateMonitorDependenciesRequest = exports.monitorEcosystem = void 0;
  594. const chalk_1 = __webpack_require__(32589);
  595. const config_1 = __webpack_require__(25425);
  596. const is_ci_1 = __webpack_require__(10090);
  597. const promise_1 = __webpack_require__(90430);
  598. const spinner_1 = __webpack_require__(86766);
  599. const plugins_1 = __webpack_require__(78053);
  600. const formatters_1 = __webpack_require__(81329);
  601. const get_extra_project_count_1 = __webpack_require__(34355);
  602. const errors_1 = __webpack_require__(55191);
  603. const policy_1 = __webpack_require__(4669);
  604. const api_token_1 = __webpack_require__(95181);
  605. const resolve_monitor_facts_1 = __webpack_require__(47630);
  606. const monitor_1 = __webpack_require__(3708);
  607. const common_1 = __webpack_require__(69813);
  608. const policy_2 = __webpack_require__(32615);
  609. const SEPARATOR = '\n-------------------------------------------------------\n';
  610. async function monitorEcosystem(ecosystem, paths, options, contributors) {
  611. const plugin = plugins_1.getPlugin(ecosystem);
  612. monitor_1.validateTags(options);
  613. monitor_1.validateProjectAttributes(options);
  614. const scanResultsByPath = {};
  615. for (const path of paths) {
  616. try {
  617. await spinner_1.spinner(`Analyzing dependencies in ${path}`);
  618. options.path = path;
  619. const pluginResponse = await plugin.scan(options);
  620. scanResultsByPath[path] = pluginResponse.scanResults;
  621. const policy = await policy_2.findAndLoadPolicy(path, 'cpp', options);
  622. if (policy) {
  623. scanResultsByPath[path].forEach((scanResult) => (scanResult.policy = policy.toString()));
  624. }
  625. }
  626. catch (error) {
  627. if (ecosystem === 'docker' &&
  628. error.statusCode === 401 &&
  629. error.message === 'authentication required') {
  630. throw new errors_1.DockerImageNotFoundError(path);
  631. }
  632. if (ecosystem === 'docker' && error.message === 'invalid image format') {
  633. throw new errors_1.DockerImageNotFoundError(path);
  634. }
  635. throw error;
  636. }
  637. finally {
  638. spinner_1.spinner.clearAll();
  639. }
  640. }
  641. const [monitorResults, errors] = await selectAndExecuteMonitorStrategy(ecosystem, scanResultsByPath, options, contributors);
  642. return [monitorResults, errors];
  643. }
  644. exports.monitorEcosystem = monitorEcosystem;
  645. async function selectAndExecuteMonitorStrategy(ecosystem, scanResultsByPath, options, contributors) {
  646. return common_1.isUnmanagedEcosystem(ecosystem)
  647. ? await resolve_monitor_facts_1.resolveAndMonitorFacts(scanResultsByPath, options, contributors)
  648. : await monitorDependencies(scanResultsByPath, options);
  649. }
  650. async function generateMonitorDependenciesRequest(scanResult, options) {
  651. // WARNING! This mutates the payload. The project name logic should be handled in the plugin.
  652. scanResult.name =
  653. options['project-name'] || config_1.default.PROJECT_NAME || scanResult.name;
  654. // WARNING! This mutates the payload. Policy logic should be in the plugin.
  655. const policy = await policy_1.findAndLoadPolicyForScanResult(scanResult, options);
  656. if (policy !== undefined) {
  657. scanResult.policy = policy.toString();
  658. }
  659. return {
  660. scanResult,
  661. method: 'cli',
  662. projectName: options['project-name'] || config_1.default.PROJECT_NAME || undefined,
  663. tags: monitor_1.generateTags(options),
  664. attributes: monitor_1.generateProjectAttributes(options),
  665. };
  666. }
  667. exports.generateMonitorDependenciesRequest = generateMonitorDependenciesRequest;
  668. async function monitorDependencies(scans, options) {
  669. const results = [];
  670. const errors = [];
  671. for (const [path, scanResults] of Object.entries(scans)) {
  672. await spinner_1.spinner(`Monitoring dependencies in ${path}`);
  673. for (const scanResult of scanResults) {
  674. const monitorDependenciesRequest = await generateMonitorDependenciesRequest(scanResult, options);
  675. const configOrg = config_1.default.org ? decodeURIComponent(config_1.default.org) : undefined;
  676. const payload = {
  677. method: 'PUT',
  678. url: `${config_1.default.API}/monitor-dependencies`,
  679. json: true,
  680. headers: {
  681. 'x-is-ci': is_ci_1.isCI(),
  682. authorization: api_token_1.getAuthHeader(),
  683. },
  684. body: monitorDependenciesRequest,
  685. qs: {
  686. org: options.org || configOrg,
  687. },
  688. };
  689. try {
  690. const response = await promise_1.makeRequest(payload);
  691. results.push({
  692. ...response,
  693. path,
  694. scanResult,
  695. });
  696. }
  697. catch (error) {
  698. if (error.code === 401) {
  699. throw errors_1.AuthFailedError();
  700. }
  701. if (error.code >= 400 && error.code < 500) {
  702. throw new errors_1.MonitorError(error.code, error.message);
  703. }
  704. errors.push({
  705. error: 'Could not monitor dependencies in ' + path,
  706. path,
  707. scanResult,
  708. });
  709. }
  710. }
  711. spinner_1.spinner.clearAll();
  712. }
  713. return [results, errors];
  714. }
  715. async function getFormattedMonitorOutput(results, monitorResults, errors, options) {
  716. for (const monitorResult of monitorResults) {
  717. let monOutput = '';
  718. if (monitorResult.ok) {
  719. monOutput = formatters_1.formatMonitorOutput(monitorResult.scanResult.identity.type, monitorResult, options, monitorResult.projectName, await get_extra_project_count_1.getExtraProjectCount(monitorResult.path, options,
  720. // TODO: Fix to pass the old "inspectResult.plugin.meta.allSubProjectNames", which ecosystem uses this?
  721. // "allSubProjectNames" can become a Fact returned by a plugin.
  722. {}));
  723. }
  724. else {
  725. monOutput = formatters_1.formatErrorMonitorOutput(monitorResult.scanResult.identity.type, monitorResult, options);
  726. }
  727. results.push({
  728. ok: true,
  729. data: monOutput,
  730. path: monitorResult.path,
  731. projectName: monitorResult.id,
  732. });
  733. }
  734. for (const monitorError of errors) {
  735. results.push({
  736. ok: false,
  737. data: new errors_1.MonitorError(500, monitorError.error),
  738. path: monitorError.path,
  739. });
  740. }
  741. const outputString = results
  742. .map((res) => {
  743. if (res.ok) {
  744. return res.data;
  745. }
  746. const errorMessage = res.data && res.data.userMessage
  747. ? chalk_1.default.bold.red(res.data.userMessage)
  748. : res.data
  749. ? res.data.message
  750. : 'Unknown error occurred.';
  751. return (chalk_1.default.bold.white('\nMonitoring ' + res.path + '...\n\n') + errorMessage);
  752. })
  753. .join('\n' + SEPARATOR);
  754. if (results.every((res) => res.ok)) {
  755. return outputString;
  756. }
  757. throw new Error(outputString);
  758. }
  759. exports.getFormattedMonitorOutput = getFormattedMonitorOutput;
  760. /***/ }),
  761. /***/ 33077:
  762. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  763. "use strict";
  764. Object.defineProperty(exports, "__esModule", ({ value: true }));
  765. exports.extractAndApplyPluginAnalytics = void 0;
  766. const analytics = __webpack_require__(82744);
  767. function extractAndApplyPluginAnalytics(pluginAnalytics, asyncRequestToken) {
  768. if (asyncRequestToken) {
  769. analytics.add('asyncRequestToken', asyncRequestToken);
  770. }
  771. for (const { name, data } of pluginAnalytics) {
  772. analytics.add(name, data);
  773. }
  774. }
  775. exports.extractAndApplyPluginAnalytics = extractAndApplyPluginAnalytics;
  776. /***/ }),
  777. /***/ 78053:
  778. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  779. "use strict";
  780. Object.defineProperty(exports, "__esModule", ({ value: true }));
  781. exports.getPlugin = void 0;
  782. const cppPlugin = __webpack_require__(96957);
  783. const dockerPlugin = __webpack_require__(61165);
  784. const sast_1 = __webpack_require__(93221);
  785. const EcosystemPlugins = {
  786. cpp: cppPlugin,
  787. // TODO: not any
  788. docker: dockerPlugin,
  789. code: sast_1.codePlugin,
  790. };
  791. function getPlugin(ecosystem) {
  792. return EcosystemPlugins[ecosystem];
  793. }
  794. exports.getPlugin = getPlugin;
  795. /***/ }),
  796. /***/ 4669:
  797. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  798. "use strict";
  799. Object.defineProperty(exports, "__esModule", ({ value: true }));
  800. exports.filterIgnoredIssues = exports.findAndLoadPolicyForScanResult = void 0;
  801. const path = __webpack_require__(85622);
  802. const policy_1 = __webpack_require__(32615);
  803. async function findAndLoadPolicyForScanResult(scanResult, options) {
  804. const targetFileRelativePath = scanResult.identity.targetFile
  805. ? path.join(path.resolve(`${options.path}`), scanResult.identity.targetFile)
  806. : undefined;
  807. const targetFileDir = targetFileRelativePath
  808. ? path.parse(targetFileRelativePath).dir
  809. : undefined;
  810. const scanType = options.docker
  811. ? 'docker'
  812. : scanResult.identity.type;
  813. // TODO: fix this and send only send when we used resolve-deps for node
  814. // it should be a ExpandedPkgTree type instead
  815. const packageExpanded = undefined;
  816. const policy = (await policy_1.findAndLoadPolicy(options.path, scanType, options, packageExpanded, targetFileDir)); // TODO: findAndLoadPolicy() does not return a string!
  817. return policy;
  818. }
  819. exports.findAndLoadPolicyForScanResult = findAndLoadPolicyForScanResult;
  820. function filterIgnoredIssues(issues, issuesData, policy) {
  821. if (!(policy === null || policy === void 0 ? void 0 : policy.ignore)) {
  822. return [issues, issuesData];
  823. }
  824. const filteredIssuesData = { ...issuesData };
  825. const filteredIssues = issues.filter((issue) => {
  826. const ignoredIssue = policy.ignore[issue.issueId];
  827. if (!ignoredIssue) {
  828. return true;
  829. }
  830. const allResourcesRule = ignoredIssue.find((element) => '*' in element);
  831. if (!allResourcesRule) {
  832. return true;
  833. }
  834. const expiredIgnoreRule = new Date(allResourcesRule['*'].expires) < new Date();
  835. if (!expiredIgnoreRule) {
  836. delete filteredIssuesData[issue.issueId];
  837. return false;
  838. }
  839. return true;
  840. });
  841. return [filteredIssues, filteredIssuesData];
  842. }
  843. exports.filterIgnoredIssues = filterIgnoredIssues;
  844. /***/ }),
  845. /***/ 47630:
  846. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  847. "use strict";
  848. Object.defineProperty(exports, "__esModule", ({ value: true }));
  849. exports.resolveAndMonitorFacts = void 0;
  850. const spinner_1 = __webpack_require__(86766);
  851. const polling_monitor_1 = __webpack_require__(59354);
  852. const plugin_analytics_1 = __webpack_require__(33077);
  853. const errors_1 = __webpack_require__(55191);
  854. const common_1 = __webpack_require__(74434);
  855. async function resolveAndMonitorFacts(scans, options, contributors) {
  856. const results = [];
  857. const errors = [];
  858. for (const [path, scanResults] of Object.entries(scans)) {
  859. await spinner_1.spinner(`Resolving and Monitoring fileSignatures in ${path}`);
  860. for (const scanResult of scanResults) {
  861. try {
  862. const res = await polling_monitor_1.requestMonitorPollingToken(options, true, scanResult);
  863. if (scanResult.analytics) {
  864. plugin_analytics_1.extractAndApplyPluginAnalytics(scanResult.analytics, res.token);
  865. }
  866. const resolutionMeta = common_1.extractResolutionMetaFromScanResult(scanResult);
  867. const { maxAttempts, pollInterval } = res.pollingTask;
  868. const attemptsCount = 0;
  869. const response = await polling_monitor_1.pollingMonitorWithTokenUntilDone(res.token, true, options, pollInterval, attemptsCount, maxAttempts, resolutionMeta, contributors);
  870. const ecosystemMonitorResult = {
  871. ...response,
  872. path,
  873. scanResult,
  874. };
  875. results.push(ecosystemMonitorResult);
  876. }
  877. catch (error) {
  878. if (error.code === 401) {
  879. throw errors_1.AuthFailedError();
  880. }
  881. if (error.code >= 400 && error.code < 500) {
  882. throw new errors_1.MonitorError(error.code, error.message);
  883. }
  884. errors.push({
  885. error: 'Could not monitor dependencies in ' + path,
  886. path,
  887. scanResult,
  888. });
  889. }
  890. }
  891. spinner_1.spinner.clearAll();
  892. }
  893. return [results, errors];
  894. }
  895. exports.resolveAndMonitorFacts = resolveAndMonitorFacts;
  896. /***/ }),
  897. /***/ 85164:
  898. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  899. "use strict";
  900. Object.defineProperty(exports, "__esModule", ({ value: true }));
  901. exports.resolveAndTestFacts = void 0;
  902. const spinner_1 = __webpack_require__(86766);
  903. const polling_test_1 = __webpack_require__(77584);
  904. const plugin_analytics_1 = __webpack_require__(33077);
  905. const policy_1 = __webpack_require__(32615);
  906. const policy_2 = __webpack_require__(4669);
  907. async function resolveAndTestFacts(ecosystem, scans, options) {
  908. var _a, _b, _c, _d, _e;
  909. const results = [];
  910. const errors = [];
  911. const packageManager = 'Unmanaged (C/C++)';
  912. for (const [path, scanResults] of Object.entries(scans)) {
  913. await spinner_1.spinner(`Resolving and Testing fileSignatures in ${path}`);
  914. for (const scanResult of scanResults) {
  915. try {
  916. const res = await polling_test_1.requestTestPollingToken(options, true, scanResult);
  917. if (scanResult.analytics) {
  918. plugin_analytics_1.extractAndApplyPluginAnalytics(scanResult.analytics, res.token);
  919. }
  920. const { maxAttempts, pollInterval } = res.pollingTask;
  921. const attemptsCount = 0;
  922. const response = await polling_test_1.pollingTestWithTokenUntilDone(res.token, ecosystem, options, pollInterval, attemptsCount, maxAttempts);
  923. const policy = await policy_1.findAndLoadPolicy(path, 'cpp', options);
  924. const [issues, issuesData] = policy_2.filterIgnoredIssues(response.issues, response.issuesData, policy);
  925. const issuesMap = new Map();
  926. response.issues.forEach((i) => {
  927. issuesMap[i.issueId] = i;
  928. });
  929. const vulnerabilities = [];
  930. for (const issuesDataKey in response.issuesData) {
  931. const issueData = response.issuesData[issuesDataKey];
  932. const pkgCoordinate = `${issuesMap[issuesDataKey].pkgName}@${issuesMap[issuesDataKey].pkgVersion}`;
  933. issueData.from = [pkgCoordinate];
  934. issueData.name = pkgCoordinate;
  935. issueData.packageManager = packageManager;
  936. vulnerabilities.push(issueData);
  937. }
  938. const dependencyCount = (_e = (_d = (_c = (_b = (_a = response === null || response === void 0 ? void 0 : response.depGraphData) === null || _a === void 0 ? void 0 : _a.graph) === null || _b === void 0 ? void 0 : _b.nodes) === null || _c === void 0 ? void 0 : _c.find((graphNode) => {
  939. return graphNode.nodeId === 'root-node';
  940. })) === null || _d === void 0 ? void 0 : _d.deps) === null || _e === void 0 ? void 0 : _e.length;
  941. results.push({
  942. issues,
  943. issuesData,
  944. depGraphData: response === null || response === void 0 ? void 0 : response.depGraphData,
  945. depsFilePaths: response === null || response === void 0 ? void 0 : response.depsFilePaths,
  946. fileSignaturesDetails: response === null || response === void 0 ? void 0 : response.fileSignaturesDetails,
  947. vulnerabilities,
  948. path,
  949. dependencyCount,
  950. packageManager,
  951. });
  952. }
  953. catch (error) {
  954. const hasStatusCodeError = error.code >= 400 && error.code <= 500;
  955. if (hasStatusCodeError) {
  956. errors.push(error.message);
  957. continue;
  958. }
  959. const failedPath = path ? `in ${path}` : '.';
  960. errors.push(`Could not test dependencies ${failedPath}`);
  961. }
  962. }
  963. }
  964. spinner_1.spinner.clearAll();
  965. return [results, errors];
  966. }
  967. exports.resolveAndTestFacts = resolveAndTestFacts;
  968. /***/ }),
  969. /***/ 60937:
  970. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  971. "use strict";
  972. Object.defineProperty(exports, "__esModule", ({ value: true }));
  973. exports.selectAndExecuteTestStrategy = exports.testEcosystem = void 0;
  974. const config_1 = __webpack_require__(25425);
  975. const is_ci_1 = __webpack_require__(10090);
  976. const promise_1 = __webpack_require__(90430);
  977. const types_1 = __webpack_require__(55246);
  978. const spinner_1 = __webpack_require__(86766);
  979. const plugins_1 = __webpack_require__(78053);
  980. const common_1 = __webpack_require__(53110);
  981. const api_token_1 = __webpack_require__(95181);
  982. const resolve_test_facts_1 = __webpack_require__(85164);
  983. const common_2 = __webpack_require__(69813);
  984. async function testEcosystem(ecosystem, paths, options) {
  985. const plugin = plugins_1.getPlugin(ecosystem);
  986. // TODO: this is an intermediate step before consolidating ecosystem plugins
  987. // to accept flows that act differently in the testDependencies step
  988. if (plugin.test) {
  989. const { readableResult: res, sarifResult: sarifRes } = await plugin.test(paths, options);
  990. return types_1.TestCommandResult.createHumanReadableTestCommandResult(res, '', sarifRes);
  991. }
  992. const scanResultsByPath = {};
  993. for (const path of paths) {
  994. await spinner_1.spinner(`Scanning dependencies in ${path}`);
  995. options.path = path;
  996. const pluginResponse = await plugin.scan(options);
  997. scanResultsByPath[path] = pluginResponse.scanResults;
  998. }
  999. spinner_1.spinner.clearAll();
  1000. const [testResults, errors] = await selectAndExecuteTestStrategy(ecosystem, scanResultsByPath, options);
  1001. const stringifiedData = JSON.stringify(testResults, null, 2);
  1002. if (options.json) {
  1003. return types_1.TestCommandResult.createJsonTestCommandResult(stringifiedData);
  1004. }
  1005. const emptyResults = [];
  1006. const scanResults = emptyResults.concat(...Object.values(scanResultsByPath));
  1007. const readableResult = await plugin.display(scanResults, testResults, errors, options);
  1008. return types_1.TestCommandResult.createHumanReadableTestCommandResult(readableResult, stringifiedData);
  1009. }
  1010. exports.testEcosystem = testEcosystem;
  1011. async function selectAndExecuteTestStrategy(ecosystem, scanResultsByPath, options) {
  1012. return common_2.isUnmanagedEcosystem(ecosystem)
  1013. ? await resolve_test_facts_1.resolveAndTestFacts(ecosystem, scanResultsByPath, options)
  1014. : await testDependencies(scanResultsByPath, options);
  1015. }
  1016. exports.selectAndExecuteTestStrategy = selectAndExecuteTestStrategy;
  1017. async function testDependencies(scans, options) {
  1018. const results = [];
  1019. const errors = [];
  1020. for (const [path, scanResults] of Object.entries(scans)) {
  1021. await spinner_1.spinner(`Testing dependencies in ${path}`);
  1022. for (const scanResult of scanResults) {
  1023. const payload = {
  1024. method: 'POST',
  1025. url: `${config_1.default.API}/test-dependencies`,
  1026. json: true,
  1027. headers: {
  1028. 'x-is-ci': is_ci_1.isCI(),
  1029. authorization: api_token_1.getAuthHeader(),
  1030. },
  1031. body: {
  1032. scanResult,
  1033. },
  1034. qs: common_1.assembleQueryString(options),
  1035. };
  1036. try {
  1037. const response = await promise_1.makeRequest(payload);
  1038. results.push({
  1039. issues: response.result.issues,
  1040. issuesData: response.result.issuesData,
  1041. depGraphData: response.result.depGraphData,
  1042. });
  1043. }
  1044. catch (error) {
  1045. if (error.code >= 400 && error.code < 500) {
  1046. throw new Error(error.message);
  1047. }
  1048. errors.push('Could not test dependencies in ' + path);
  1049. }
  1050. }
  1051. }
  1052. spinner_1.spinner.clearAll();
  1053. return [results, errors];
  1054. }
  1055. /***/ }),
  1056. /***/ 86033:
  1057. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  1058. "use strict";
  1059. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1060. exports.InvalidRemoteUrlError = void 0;
  1061. const custom_error_1 = __webpack_require__(17188);
  1062. class InvalidRemoteUrlError extends custom_error_1.CustomError {
  1063. constructor() {
  1064. super(InvalidRemoteUrlError.ERROR_MESSAGE);
  1065. }
  1066. }
  1067. exports.InvalidRemoteUrlError = InvalidRemoteUrlError;
  1068. InvalidRemoteUrlError.ERROR_MESSAGE = 'Invalid argument provided for --remote-repo-url. Value must be a string.';
  1069. /***/ }),
  1070. /***/ 46123:
  1071. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  1072. "use strict";
  1073. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1074. exports.find = exports.getStats = exports.readDirectory = void 0;
  1075. const fs = __webpack_require__(35747);
  1076. const pathLib = __webpack_require__(85622);
  1077. const sortBy = __webpack_require__(58254);
  1078. const groupBy = __webpack_require__(20276);
  1079. const detect_1 = __webpack_require__(45318);
  1080. const debugModule = __webpack_require__(15158);
  1081. const debug = debugModule('snyk:find-files');
  1082. // TODO: use util.promisify once we move to node 8
  1083. /**
  1084. * Returns files inside given file path.
  1085. *
  1086. * @param path file path.
  1087. */
  1088. async function readDirectory(path) {
  1089. return await new Promise((resolve, reject) => {
  1090. fs.readdir(path, (err, files) => {
  1091. if (err) {
  1092. reject(err);
  1093. }
  1094. resolve(files);
  1095. });
  1096. });
  1097. }
  1098. exports.readDirectory = readDirectory;
  1099. /**
  1100. * Returns file stats object for given file path.
  1101. *
  1102. * @param path path to file or directory.
  1103. */
  1104. async function getStats(path) {
  1105. return await new Promise((resolve, reject) => {
  1106. fs.stat(path, (err, stats) => {
  1107. if (err) {
  1108. reject(err);
  1109. }
  1110. resolve(stats);
  1111. });
  1112. });
  1113. }
  1114. exports.getStats = getStats;
  1115. /**
  1116. * Find all files in given search path. Returns paths to files found.
  1117. *
  1118. * @param path file path to search.
  1119. * @param ignore (optional) files to ignore. Will always ignore node_modules.
  1120. * @param filter (optional) file names to find. If not provided all files are returned.
  1121. * @param levelsDeep (optional) how many levels deep to search, defaults to two, this path and one sub directory.
  1122. */
  1123. async function find(path, ignore = [], filter = [], levelsDeep = 4) {
  1124. const found = [];
  1125. const foundAll = [];
  1126. // ensure we ignore find against node_modules path.
  1127. if (path.endsWith('node_modules')) {
  1128. return { files: found, allFilesFound: foundAll };
  1129. }
  1130. // ensure node_modules is always ignored
  1131. if (!ignore.includes('node_modules')) {
  1132. ignore.push('node_modules');
  1133. }
  1134. try {
  1135. if (levelsDeep < 0) {
  1136. return { files: found, allFilesFound: foundAll };
  1137. }
  1138. else {
  1139. levelsDeep--;
  1140. }
  1141. const fileStats = await getStats(path);
  1142. if (fileStats.isDirectory()) {
  1143. const { files, allFilesFound } = await findInDirectory(path, ignore, filter, levelsDeep);
  1144. found.push(...files);
  1145. foundAll.push(...allFilesFound);
  1146. }
  1147. else if (fileStats.isFile()) {
  1148. const fileFound = findFile(path, filter);
  1149. if (fileFound) {
  1150. found.push(fileFound);
  1151. foundAll.push(fileFound);
  1152. }
  1153. }
  1154. const filteredOutFiles = foundAll.filter((f) => !found.includes(f));
  1155. if (filteredOutFiles.length) {
  1156. debug(`Filtered out ${filteredOutFiles.length}/${foundAll.length} files: ${filteredOutFiles.join(', ')}`);
  1157. }
  1158. return { files: filterForDefaultManifests(found), allFilesFound: foundAll };
  1159. }
  1160. catch (err) {
  1161. throw new Error(`Error finding files in path '${path}'.\n${err.message}`);
  1162. }
  1163. }
  1164. exports.find = find;
  1165. function findFile(path, filter = []) {
  1166. if (filter.length > 0) {
  1167. const filename = pathLib.basename(path);
  1168. if (filter.includes(filename)) {
  1169. return path;
  1170. }
  1171. }
  1172. else {
  1173. return path;
  1174. }
  1175. return null;
  1176. }
  1177. async function findInDirectory(path, ignore = [], filter = [], levelsDeep = 4) {
  1178. const files = await readDirectory(path);
  1179. const toFind = files
  1180. .filter((file) => !ignore.includes(file))
  1181. .map((file) => {
  1182. const resolvedPath = pathLib.resolve(path, file);
  1183. if (!fs.existsSync(resolvedPath)) {
  1184. debug('File does not seem to exist, skipping: ', file);
  1185. return { files: [], allFilesFound: [] };
  1186. }
  1187. return find(resolvedPath, ignore, filter, levelsDeep);
  1188. });
  1189. const found = await Promise.all(toFind);
  1190. return {
  1191. files: Array.prototype.concat.apply([], found.map((f) => f.files)),
  1192. allFilesFound: Array.prototype.concat.apply([], found.map((f) => f.allFilesFound)),
  1193. };
  1194. }
  1195. function filterForDefaultManifests(files) {
  1196. // take all the files in the same dir & filter out
  1197. // based on package Manager
  1198. if (files.length <= 1) {
  1199. return files;
  1200. }
  1201. const filteredFiles = [];
  1202. const beforeSort = files
  1203. .filter(Boolean)
  1204. .filter((p) => fs.existsSync(p))
  1205. .map((p) => ({
  1206. path: p,
  1207. ...pathLib.parse(p),
  1208. packageManager: detectProjectTypeFromFile(p),
  1209. }));
  1210. const sorted = sortBy(beforeSort, 'dir');
  1211. const foundFiles = groupBy(sorted, 'dir');
  1212. for (const directory of Object.keys(foundFiles)) {
  1213. const filesInDirectory = foundFiles[directory];
  1214. const beforeGroup = filesInDirectory.filter((p) => !!p.packageManager);
  1215. const groupedFiles = groupBy(beforeGroup, 'packageManager');
  1216. for (const packageManager of Object.keys(groupedFiles)) {
  1217. const filesPerPackageManager = groupedFiles[packageManager];
  1218. if (filesPerPackageManager.length <= 1) {
  1219. const shouldSkip = shouldSkipAddingFile(packageManager, filesPerPackageManager[0].path, filteredFiles);
  1220. if (shouldSkip) {
  1221. continue;
  1222. }
  1223. filteredFiles.push(filesPerPackageManager[0].path);
  1224. continue;
  1225. }
  1226. const defaultManifestFileName = chooseBestManifest(filesPerPackageManager, packageManager);
  1227. if (defaultManifestFileName) {
  1228. const shouldSkip = shouldSkipAddingFile(packageManager, filesPerPackageManager[0].path, filteredFiles);
  1229. if (shouldSkip) {
  1230. continue;
  1231. }
  1232. filteredFiles.push(defaultManifestFileName);
  1233. }
  1234. }
  1235. }
  1236. return filteredFiles;
  1237. }
  1238. function detectProjectTypeFromFile(file) {
  1239. try {
  1240. const packageManager = detect_1.detectPackageManagerFromFile(file);
  1241. if (['yarn', 'npm'].includes(packageManager)) {
  1242. return 'node';
  1243. }
  1244. return packageManager;
  1245. }
  1246. catch (error) {
  1247. return null;
  1248. }
  1249. }
  1250. function shouldSkipAddingFile(packageManager, filePath, filteredFiles) {
  1251. if (['gradle'].includes(packageManager) && filePath) {
  1252. const rootGradleFile = filteredFiles
  1253. .filter((targetFile) => targetFile.endsWith('build.gradle') ||
  1254. targetFile.endsWith('build.gradle.kts'))
  1255. .filter((targetFile) => {
  1256. const parsedPath = pathLib.parse(targetFile);
  1257. const relativePath = pathLib.relative(parsedPath.dir, filePath);
  1258. return !relativePath.startsWith(`..${pathLib.sep}`);
  1259. });
  1260. return !!rootGradleFile.length;
  1261. }
  1262. return false;
  1263. }
  1264. function chooseBestManifest(files, projectType) {
  1265. switch (projectType) {
  1266. case 'node': {
  1267. const lockFile = files.filter((path) => ['package-lock.json', 'yarn.lock'].includes(path.base))[0];
  1268. debug(`Encountered multiple node lockfiles files, defaulting to ${lockFile.path}`);
  1269. if (lockFile) {
  1270. return lockFile.path;
  1271. }
  1272. const packageJson = files.filter((path) => ['package.json'].includes(path.base))[0];
  1273. debug(`Encountered multiple npm manifest files, defaulting to ${packageJson.path}`);
  1274. return packageJson.path;
  1275. }
  1276. case 'rubygems': {
  1277. const defaultManifest = files.filter((path) => ['Gemfile.lock'].includes(path.base))[0];
  1278. debug(`Encountered multiple gem manifest files, defaulting to ${defaultManifest.path}`);
  1279. return defaultManifest.path;
  1280. }
  1281. case 'cocoapods': {
  1282. const defaultManifest = files.filter((path) => ['Podfile'].includes(path.base))[0];
  1283. debug(`Encountered multiple cocoapods manifest files, defaulting to ${defaultManifest.path}`);
  1284. return defaultManifest.path;
  1285. }
  1286. case 'pip': {
  1287. const defaultManifest = files.filter((path) => ['Pipfile'].includes(path.base))[0];
  1288. debug(`Encountered multiple pip manifest files, defaulting to ${defaultManifest.path}`);
  1289. return defaultManifest.path;
  1290. }
  1291. case 'gradle': {
  1292. const defaultManifest = files.filter((path) => ['build.gradle'].includes(path.base))[0];
  1293. debug(`Encountered multiple gradle manifest files, defaulting to ${defaultManifest.path}`);
  1294. return defaultManifest.path;
  1295. }
  1296. case 'poetry': {
  1297. const defaultManifest = files.filter((path) => ['pyproject.toml'].includes(path.base))[0];
  1298. debug(`Encountered multiple poetry manifest files, defaulting to ${defaultManifest.path}`);
  1299. return defaultManifest.path;
  1300. }
  1301. case 'hex': {
  1302. const defaultManifest = files.filter((path) => ['mix.exs'].includes(path.base))[0];
  1303. debug(`Encountered multiple hex manifest files, defaulting to ${defaultManifest.path}`);
  1304. return defaultManifest.path;
  1305. }
  1306. default: {
  1307. return null;
  1308. }
  1309. }
  1310. }
  1311. /***/ }),
  1312. /***/ 18362:
  1313. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  1314. "use strict";
  1315. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1316. exports.dockerRemediationForDisplay = void 0;
  1317. const chalk_1 = __webpack_require__(32589);
  1318. function dockerRemediationForDisplay(res) {
  1319. if (!res.docker || !res.docker.baseImageRemediation) {
  1320. return '';
  1321. }
  1322. const { advice, message } = res.docker.baseImageRemediation;
  1323. const out = [];
  1324. if (advice) {
  1325. for (const item of advice) {
  1326. out.push(getTerminalStringFormatter(item)(item.message));
  1327. }
  1328. }
  1329. else if (message) {
  1330. out.push(message);
  1331. }
  1332. else {
  1333. return '';
  1334. }
  1335. return `\n\n${out.join('\n')}`;
  1336. }
  1337. exports.dockerRemediationForDisplay = dockerRemediationForDisplay;
  1338. function getTerminalStringFormatter({ color, bold, }) {
  1339. let formatter = chalk_1.default;
  1340. if (color && formatter[color]) {
  1341. formatter = formatter[color];
  1342. }
  1343. if (bold) {
  1344. formatter = formatter.bold;
  1345. }
  1346. return formatter;
  1347. }
  1348. /***/ }),
  1349. /***/ 4928:
  1350. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  1351. "use strict";
  1352. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1353. exports.createDockerBinaryHeading = void 0;
  1354. const values = __webpack_require__(17720);
  1355. const chalk_1 = __webpack_require__(32589);
  1356. function createDockerBinaryHeading(pkgInfo) {
  1357. const binaryName = pkgInfo.pkg.name;
  1358. const binaryVersion = pkgInfo.pkg.version;
  1359. const numOfVulns = values(pkgInfo.issues).length;
  1360. const vulnCountText = numOfVulns > 1 ? 'vulnerabilities' : 'vulnerability';
  1361. return numOfVulns
  1362. ? chalk_1.default.bold.white(`------------ Detected ${numOfVulns} ${vulnCountText}` +
  1363. ` for ${binaryName}@${binaryVersion} ------------`, '\n')
  1364. : '';
  1365. }
  1366. exports.createDockerBinaryHeading = createDockerBinaryHeading;
  1367. /***/ }),
  1368. /***/ 80576:
  1369. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  1370. "use strict";
  1371. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1372. exports.formatDockerBinariesIssues = void 0;
  1373. const values = __webpack_require__(17720);
  1374. const format_docker_binary_heading_1 = __webpack_require__(4928);
  1375. const legacy_format_issue_1 = __webpack_require__(63540);
  1376. function formatDockerBinariesIssues(dockerBinariesSortedGroupedVulns, binariesVulns, options) {
  1377. const binariesIssuesOutput = [];
  1378. for (const pkgInfo of values(binariesVulns.affectedPkgs)) {
  1379. binariesIssuesOutput.push(format_docker_binary_heading_1.createDockerBinaryHeading(pkgInfo));
  1380. const binaryIssues = dockerBinariesSortedGroupedVulns.filter((vuln) => vuln.metadata.name === pkgInfo.pkg.name);
  1381. const formattedBinaryIssues = binaryIssues.map((vuln) => legacy_format_issue_1.formatIssues(vuln, options));
  1382. binariesIssuesOutput.push(formattedBinaryIssues.join('\n\n'));
  1383. }
  1384. return binariesIssuesOutput;
  1385. }
  1386. exports.formatDockerBinariesIssues = formatDockerBinariesIssues;
  1387. /***/ }),
  1388. /***/ 41287:
  1389. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  1390. "use strict";
  1391. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1392. var format_docker_advice_1 = __webpack_require__(18362);
  1393. Object.defineProperty(exports, "dockerRemediationForDisplay", ({ enumerable: true, get: function () { return format_docker_advice_1.dockerRemediationForDisplay; } }));
  1394. var format_docker_binary_issues_1 = __webpack_require__(80576);
  1395. Object.defineProperty(exports, "formatDockerBinariesIssues", ({ enumerable: true, get: function () { return format_docker_binary_issues_1.formatDockerBinariesIssues; } }));
  1396. var format_docker_binary_heading_1 = __webpack_require__(4928);
  1397. Object.defineProperty(exports, "createDockerBinaryHeading", ({ enumerable: true, get: function () { return format_docker_binary_heading_1.createDockerBinaryHeading; } }));
  1398. /***/ }),
  1399. /***/ 13232:
  1400. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  1401. "use strict";
  1402. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1403. exports.summariseErrorResults = void 0;
  1404. const errors_1 = __webpack_require__(55191);
  1405. function summariseErrorResults(errorResultsLength) {
  1406. const projects = errorResultsLength > 1 ? 'projects' : 'project';
  1407. if (errorResultsLength > 0) {
  1408. return errors_1.errorMessageWithRetry(` Failed to test ${errorResultsLength} ${projects}.`);
  1409. }
  1410. return '';
  1411. }
  1412. exports.summariseErrorResults = summariseErrorResults;
  1413. /***/ }),
  1414. /***/ 4040:
  1415. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  1416. "use strict";
  1417. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1418. exports.formatMonitorOutput = exports.formatErrorMonitorOutput = void 0;
  1419. const assign = __webpack_require__(31730);
  1420. const chalk_1 = __webpack_require__(32589);
  1421. const url = __webpack_require__(78835);
  1422. const config_1 = __webpack_require__(25425);
  1423. const show_multi_scan_tip_1 = __webpack_require__(95100);
  1424. function formatErrorMonitorOutput(packageManager, res, options, projectName) {
  1425. const humanReadableName = projectName
  1426. ? `${res.path} (${projectName})`
  1427. : res.path;
  1428. const strOutput = chalk_1.default.bold.white('\nMonitoring ' + humanReadableName + '...\n\n') +
  1429. '\n\n' +
  1430. (packageManager === 'maven'
  1431. ? chalk_1.default.yellow('Detected 0 dependencies (no project created)')
  1432. : '');
  1433. return options.json
  1434. ? JSON.stringify(assign({}, res, {
  1435. packageManager,
  1436. }))
  1437. : strOutput;
  1438. }
  1439. exports.formatErrorMonitorOutput = formatErrorMonitorOutput;
  1440. function formatMonitorOutput(packageManager, res, options, projectName, foundProjectCount) {
  1441. const manageUrl = buildManageUrl(res.id, res.org);
  1442. const multiScanTip = show_multi_scan_tip_1.showMultiScanTip(packageManager, options, foundProjectCount);
  1443. const issues = res.licensesPolicy ? 'issues' : 'vulnerabilities';
  1444. const humanReadableName = projectName
  1445. ? `${res.path} (${projectName})`
  1446. : res.path;
  1447. const strOutput = chalk_1.default.bold.white('\nMonitoring ' + humanReadableName + '...\n\n') +
  1448. 'Explore this snapshot at ' +
  1449. res.uri +
  1450. '\n\n' +
  1451. (multiScanTip ? `${multiScanTip}\n\n` : '') +
  1452. (res.isMonitored
  1453. ? 'Notifications about newly disclosed ' +
  1454. issues +
  1455. ' related ' +
  1456. 'to these dependencies will be emailed to you.\n'
  1457. : chalk_1.default.bold.red('Project is inactive, so notifications are turned ' +
  1458. 'off.\nActivate this project here: ' +
  1459. manageUrl +
  1460. '\n\n')) +
  1461. (res.trialStarted
  1462. ? chalk_1.default.yellow("You're over the free plan usage limit, \n" +
  1463. 'and are now on a free 14-day premium trial.\n' +
  1464. 'View plans here: ' +
  1465. manageUrl +
  1466. '\n\n')
  1467. : '');
  1468. return options.json
  1469. ? JSON.stringify(assign({}, res, {
  1470. manageUrl,
  1471. packageManager,
  1472. }))
  1473. : strOutput;
  1474. }
  1475. exports.formatMonitorOutput = formatMonitorOutput;
  1476. function buildManageUrl(resId, org) {
  1477. const endpoint = url.parse(config_1.default.API);
  1478. let leader = '';
  1479. if (org) {
  1480. leader = '/org/' + org;
  1481. }
  1482. endpoint.pathname = leader + '/manage';
  1483. const manageUrl = url.format(endpoint);
  1484. // TODO: what was this meant to do?
  1485. endpoint.pathname = leader + '/monitor/' + resId;
  1486. return manageUrl;
  1487. }
  1488. /***/ }),
  1489. /***/ 28001:
  1490. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  1491. "use strict";
  1492. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1493. exports.formatTestMeta = void 0;
  1494. const chalk_1 = __webpack_require__(32589);
  1495. const right_pad_1 = __webpack_require__(80627);
  1496. function formatTestMeta(res, options) {
  1497. const padToLength = 19; // chars to align
  1498. const packageManager = res.packageManager || options.packageManager;
  1499. const targetFile = res.targetFile || res.displayTargetFile || options.file;
  1500. const openSource = res.isPrivate ? 'no' : 'yes';
  1501. const meta = res.org
  1502. ? [chalk_1.default.bold(right_pad_1.rightPadWithSpaces('Organization: ', padToLength)) + res.org]
  1503. : [];
  1504. meta.push(chalk_1.default.bold(right_pad_1.rightPadWithSpaces('Package manager: ', padToLength)) +
  1505. packageManager);
  1506. if (targetFile) {
  1507. meta.push(chalk_1.default.bold(right_pad_1.rightPadWithSpaces('Target file: ', padToLength)) + targetFile);
  1508. }
  1509. if (res.projectName) {
  1510. meta.push(chalk_1.default.bold(right_pad_1.rightPadWithSpaces('Project name: ', padToLength)) +
  1511. res.projectName);
  1512. }
  1513. if (options.docker) {
  1514. meta.push(chalk_1.default.bold(right_pad_1.rightPadWithSpaces('Docker image: ', padToLength)) +
  1515. options.path);
  1516. if (res.platform) {
  1517. meta.push(chalk_1.default.bold(right_pad_1.rightPadWithSpaces('Platform: ', padToLength)) +
  1518. res.platform);
  1519. }
  1520. }
  1521. else {
  1522. meta.push(chalk_1.default.bold(right_pad_1.rightPadWithSpaces('Open source: ', padToLength)) + openSource);
  1523. meta.push(chalk_1.default.bold(right_pad_1.rightPadWithSpaces('Project path: ', padToLength)) +
  1524. options.path);
  1525. }
  1526. if (res.payloadType !== 'k8sconfig') {
  1527. const legacyRes = res;
  1528. if (legacyRes.docker && legacyRes.docker.baseImage) {
  1529. meta.push(chalk_1.default.bold(right_pad_1.rightPadWithSpaces('Base image: ', padToLength)) +
  1530. legacyRes.docker.baseImage);
  1531. }
  1532. if (legacyRes.filesystemPolicy) {
  1533. meta.push(chalk_1.default.bold(right_pad_1.rightPadWithSpaces('Local Snyk policy: ', padToLength)) +
  1534. chalk_1.default.green('found'));
  1535. if (legacyRes.ignoreSettings &&
  1536. legacyRes.ignoreSettings.disregardFilesystemIgnores) {
  1537. meta.push(chalk_1.default.bold(right_pad_1.rightPadWithSpaces('Local Snyk policy ignored: ', padToLength)) + chalk_1.default.red('yes'));
  1538. }
  1539. }
  1540. if (legacyRes.licensesPolicy) {
  1541. meta.push(chalk_1.default.bold(right_pad_1.rightPadWithSpaces('Licenses: ', padToLength)) +
  1542. chalk_1.default.green('enabled'));
  1543. }
  1544. }
  1545. return meta.join('\n');
  1546. }
  1547. exports.formatTestMeta = formatTestMeta;
  1548. /***/ }),
  1549. /***/ 27495:
  1550. /***/ ((__unused_webpack_module, exports) => {
  1551. "use strict";
  1552. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1553. exports.summariseVulnerableResults = void 0;
  1554. function summariseVulnerableResults(vulnerableResults, options) {
  1555. const vulnsLength = vulnerableResults.length;
  1556. if (vulnsLength) {
  1557. if (options.showVulnPaths) {
  1558. return `, ${vulnsLength} contained ${options.iac ? 'issues' : 'vulnerable paths'}.`;
  1559. }
  1560. return `, ${vulnsLength} had issues.`;
  1561. }
  1562. if (options.showVulnPaths) {
  1563. return ', no vulnerable paths were found.';
  1564. }
  1565. return ', no issues were found.';
  1566. }
  1567. exports.summariseVulnerableResults = summariseVulnerableResults;
  1568. /***/ }),
  1569. /***/ 24898:
  1570. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  1571. "use strict";
  1572. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1573. exports.getSeverityValue = void 0;
  1574. const common_1 = __webpack_require__(53110);
  1575. function getSeverityValue(severity) {
  1576. return common_1.SEVERITIES.find((s) => s.verboseName === severity).value;
  1577. }
  1578. exports.getSeverityValue = getSeverityValue;
  1579. /***/ }),
  1580. /***/ 41438:
  1581. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  1582. "use strict";
  1583. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1584. exports.getVulnerabilityUrl = void 0;
  1585. const config_1 = __webpack_require__(25425);
  1586. const licenseRegex = /^snyk:lic/i;
  1587. function getVulnerabilityUrl(vulnerabilityId) {
  1588. return licenseRegex.test(vulnerabilityId)
  1589. ? `${config_1.default.ROOT}/vuln/${vulnerabilityId}`
  1590. : `${config_1.default.PUBLIC_VULN_DB_URL}/vuln/${vulnerabilityId}`;
  1591. }
  1592. exports.getVulnerabilityUrl = getVulnerabilityUrl;
  1593. /***/ }),
  1594. /***/ 81329:
  1595. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  1596. "use strict";
  1597. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  1598. if (k2 === undefined) k2 = k;
  1599. Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
  1600. }) : (function(o, m, k, k2) {
  1601. if (k2 === undefined) k2 = k;
  1602. o[k2] = m[k];
  1603. }));
  1604. var __exportStar = (this && this.__exportStar) || function(m, exports) {
  1605. for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
  1606. };
  1607. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1608. var format_test_meta_1 = __webpack_require__(28001);
  1609. Object.defineProperty(exports, "formatTestMeta", ({ enumerable: true, get: function () { return format_test_meta_1.formatTestMeta; } }));
  1610. var format_vulnerable_result_summary_1 = __webpack_require__(27495);
  1611. Object.defineProperty(exports, "summariseVulnerableResults", ({ enumerable: true, get: function () { return format_vulnerable_result_summary_1.summariseVulnerableResults; } }));
  1612. var format_error_result_summary_1 = __webpack_require__(13232);
  1613. Object.defineProperty(exports, "summariseErrorResults", ({ enumerable: true, get: function () { return format_error_result_summary_1.summariseErrorResults; } }));
  1614. var legacy_format_issue_1 = __webpack_require__(63540);
  1615. Object.defineProperty(exports, "formatIssues", ({ enumerable: true, get: function () { return legacy_format_issue_1.formatIssues; } }));
  1616. var legal_license_instructions_1 = __webpack_require__(48049);
  1617. Object.defineProperty(exports, "formatLegalInstructions", ({ enumerable: true, get: function () { return legal_license_instructions_1.formatLegalInstructions; } }));
  1618. var remediation_based_format_issues_1 = __webpack_require__(57995);
  1619. Object.defineProperty(exports, "formatIssuesWithRemediation", ({ enumerable: true, get: function () { return remediation_based_format_issues_1.formatIssuesWithRemediation; } }));
  1620. var format_monitor_response_1 = __webpack_require__(4040);
  1621. Object.defineProperty(exports, "formatErrorMonitorOutput", ({ enumerable: true, get: function () { return format_monitor_response_1.formatErrorMonitorOutput; } }));
  1622. Object.defineProperty(exports, "formatMonitorOutput", ({ enumerable: true, get: function () { return format_monitor_response_1.formatMonitorOutput; } }));
  1623. __exportStar(__webpack_require__(41287), exports);
  1624. /***/ }),
  1625. /***/ 63540:
  1626. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  1627. "use strict";
  1628. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1629. exports.titleCaseText = exports.formatIssues = void 0;
  1630. const uniq = __webpack_require__(97644);
  1631. const chalk_1 = __webpack_require__(32589);
  1632. const detect_1 = __webpack_require__(45318);
  1633. const snyk_module_1 = __webpack_require__(60390);
  1634. const package_managers_1 = __webpack_require__(53847);
  1635. const legal_license_instructions_1 = __webpack_require__(48049);
  1636. const common_1 = __webpack_require__(53110);
  1637. const constants_1 = __webpack_require__(65623);
  1638. const get_vuln_url_1 = __webpack_require__(41438);
  1639. function formatIssues(vuln, options) {
  1640. const vulnID = vuln.list[0].id;
  1641. const packageManager = options.packageManager;
  1642. const localPackageTest = detect_1.isLocalFolder(options.path);
  1643. const uniquePackages = uniq(vuln.list.map((i) => {
  1644. if (i.from[1]) {
  1645. return i.from && i.from[1];
  1646. }
  1647. return i.from;
  1648. })).join(', ');
  1649. const vulnOutput = {
  1650. issueHeading: createSeverityBasedIssueHeading({
  1651. severity: vuln.metadata.severity,
  1652. originalSeverity: vuln.originalSeverity,
  1653. type: vuln.metadata.type,
  1654. packageName: vuln.metadata.name,
  1655. isNew: false,
  1656. }),
  1657. introducedThrough: ' Introduced through: ' + uniquePackages,
  1658. description: ' Description: ' + vuln.title,
  1659. info: ' Info: ' + chalk_1.default.underline(get_vuln_url_1.getVulnerabilityUrl(vulnID)),
  1660. fromPaths: createTruncatedVulnsPathsText(vuln.list, options.showVulnPaths),
  1661. extraInfo: vuln.note ? chalk_1.default.bold('\n Note: ' + vuln.note) : '',
  1662. remediationInfo: vuln.metadata.type !== 'license' && localPackageTest
  1663. ? createRemediationText(vuln, packageManager)
  1664. : '',
  1665. fixedIn: options.docker ? createFixedInText(vuln) : '',
  1666. dockerfilePackage: options.docker ? dockerfileInstructionText(vuln) : '',
  1667. legalInstructions: vuln.legalInstructionsArray
  1668. ? chalk_1.default.bold('\n Legal instructions:\n') +
  1669. ' '.repeat(2) +
  1670. legal_license_instructions_1.formatLegalInstructions(vuln.legalInstructionsArray, 2)
  1671. : '',
  1672. };
  1673. return (`${vulnOutput.issueHeading}\n` +
  1674. `${vulnOutput.description}\n` +
  1675. `${vulnOutput.info}\n` +
  1676. `${vulnOutput.introducedThrough}\n` +
  1677. vulnOutput.fromPaths +
  1678. // Optional - not always there
  1679. vulnOutput.remediationInfo +
  1680. vulnOutput.dockerfilePackage +
  1681. vulnOutput.fixedIn +
  1682. vulnOutput.extraInfo +
  1683. vulnOutput.legalInstructions);
  1684. }
  1685. exports.formatIssues = formatIssues;
  1686. function createSeverityBasedIssueHeading({ severity, originalSeverity, type, packageName, isNew, }) {
  1687. // Example: ✗ Medium severity vulnerability found in xmldom
  1688. const vulnTypeText = type === 'license' ? 'issue' : 'vulnerability';
  1689. let originalSeverityStr = '';
  1690. if (originalSeverity && originalSeverity !== severity) {
  1691. originalSeverityStr = ` (originally ${titleCaseText(originalSeverity)})`;
  1692. }
  1693. return (common_1.colorTextBySeverity(severity, '✗ ' +
  1694. titleCaseText(severity) +
  1695. ` severity${originalSeverityStr} ` +
  1696. vulnTypeText +
  1697. ' found in ' +
  1698. chalk_1.default.underline(packageName)) + chalk_1.default.bold.magenta(isNew ? ' (new)' : ''));
  1699. }
  1700. function titleCaseText(text) {
  1701. return text[0].toUpperCase() + text.slice(1);
  1702. }
  1703. exports.titleCaseText = titleCaseText;
  1704. function dockerfileInstructionText(vuln) {
  1705. if (vuln.dockerfileInstruction) {
  1706. JSON.stringify(vuln.dockerfileInstruction);
  1707. return `\n Image layer: '${vuln.dockerfileInstruction}'`;
  1708. }
  1709. if (vuln.dockerBaseImage) {
  1710. return `\n Image layer: Introduced by your base image (${vuln.dockerBaseImage})`;
  1711. }
  1712. return '';
  1713. }
  1714. function createTruncatedVulnsPathsText(vulnList, show) {
  1715. if (show === 'none') {
  1716. return '';
  1717. }
  1718. const numberOfPathsToDisplay = show === 'all' ? 1000 : 3;
  1719. const fromPathsArray = vulnList.map((i) => i.from);
  1720. const formatedFromPathsArray = fromPathsArray.map((i) => {
  1721. const fromWithoutBaseProject = i.slice(1);
  1722. // If more than one From path
  1723. if (fromWithoutBaseProject.length) {
  1724. return i.slice(1).join(constants_1.PATH_SEPARATOR);
  1725. }
  1726. // Else issue is in the core package
  1727. return i;
  1728. });
  1729. const notShownPathsNumber = fromPathsArray.length - numberOfPathsToDisplay;
  1730. const shouldTruncatePaths = fromPathsArray.length > numberOfPathsToDisplay;
  1731. const truncatedText = `\n and ${notShownPathsNumber} more...`;
  1732. const formattedPathsText = formatedFromPathsArray
  1733. .slice(0, numberOfPathsToDisplay)
  1734. .join('\n From: ');
  1735. if (fromPathsArray.length > 0) {
  1736. return (' From: ' +
  1737. formattedPathsText +
  1738. (shouldTruncatePaths ? truncatedText : ''));
  1739. }
  1740. }
  1741. function createFixedInText(vuln) {
  1742. if (vuln.nearestFixedInVersion) {
  1743. return chalk_1.default.bold('\n Fixed in: ' + vuln.nearestFixedInVersion);
  1744. }
  1745. else if (vuln.fixedIn && vuln.fixedIn.length > 0) {
  1746. return chalk_1.default.bold('\n Fixed in: ' + vuln.fixedIn.join(', '));
  1747. }
  1748. return '';
  1749. }
  1750. function createRemediationText(vuln, packageManager) {
  1751. if (vuln.fixedIn &&
  1752. package_managers_1.PINNING_SUPPORTED_PACKAGE_MANAGERS.includes(packageManager)) {
  1753. const toVersion = vuln.fixedIn.join(' or ');
  1754. const transitive = vuln.list.every((i) => i.from.length > 2);
  1755. const fromVersionArray = vuln.list.map((v) => v.from[1]);
  1756. const fromVersion = fromVersionArray[0];
  1757. if (transitive) {
  1758. return chalk_1.default.bold(`\n Remediation:\n Pin the transitive dependency ${vuln.name} to version ${toVersion}`);
  1759. }
  1760. else {
  1761. return chalk_1.default.bold(`\n Remediation:\n Upgrade direct dependency ${fromVersion} to ${vuln.name}@${toVersion}`);
  1762. }
  1763. }
  1764. if (vuln.isFixable === true) {
  1765. const upgradePathsArray = uniq(vuln.list.map((v) => {
  1766. const shouldUpgradeItself = !!v.upgradePath[0];
  1767. const shouldUpgradeDirectDep = !!v.upgradePath[1];
  1768. if (shouldUpgradeItself) {
  1769. // If we are testing a library/package like express
  1770. // Then we can suggest they get the latest version
  1771. // Example command: snyk test express@3
  1772. const selfUpgradeInfo = v.upgradePath.length > 0
  1773. ? ` (triggers upgrades to ${v.upgradePath.join(constants_1.PATH_SEPARATOR)})`
  1774. : '';
  1775. const testedPackageName = snyk_module_1.parsePackageString(v.upgradePath[0]);
  1776. return (`You've tested an outdated version of ${testedPackageName[0]}.` +
  1777. +` Upgrade to ${v.upgradePath[0]}${selfUpgradeInfo}`);
  1778. }
  1779. if (shouldUpgradeDirectDep) {
  1780. const formattedUpgradePath = v.upgradePath
  1781. .slice(1)
  1782. .join(constants_1.PATH_SEPARATOR);
  1783. const upgradeTextInfo = v.upgradePath.length
  1784. ? ` (triggers upgrades to ${formattedUpgradePath})`
  1785. : '';
  1786. return `Upgrade direct dependency ${v.from[1]} to ${v.upgradePath[1]}${upgradeTextInfo}`;
  1787. }
  1788. return 'Some paths have no direct dependency upgrade that can address this issue.';
  1789. }));
  1790. return chalk_1.default.bold(`\n Remediation:\n ${upgradePathsArray.join('\n ')}`);
  1791. }
  1792. if (vuln.fixedIn && vuln.fixedIn.length > 0) {
  1793. return createFixedInText(vuln);
  1794. }
  1795. return '';
  1796. }
  1797. /***/ }),
  1798. /***/ 48049:
  1799. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  1800. "use strict";
  1801. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1802. exports.formatLegalInstructions = void 0;
  1803. const wrap = __webpack_require__(88152);
  1804. const chalk_1 = __webpack_require__(32589);
  1805. function formatLegalInstructions(legalInstructions, paddingLength = 4) {
  1806. const legalContent = legalInstructions.map((legalData) => wrap(chalk_1.default.bold(`○ for ${legalData.licenseName}: `) + legalData.legalContent, 100)
  1807. .split('\n')
  1808. .join('\n' + ' '.repeat(paddingLength)));
  1809. return legalContent.join('\n' + ' '.repeat(paddingLength));
  1810. }
  1811. exports.formatLegalInstructions = formatLegalInstructions;
  1812. /***/ }),
  1813. /***/ 57995:
  1814. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  1815. "use strict";
  1816. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1817. exports.formatIssue = exports.printPath = exports.formatIssuesWithRemediation = void 0;
  1818. const chalk_1 = __webpack_require__(32589);
  1819. const theme_1 = __webpack_require__(86988);
  1820. const common_1 = __webpack_require__(53110);
  1821. const legal_license_instructions_1 = __webpack_require__(48049);
  1822. const constants_1 = __webpack_require__(65623);
  1823. const get_severity_value_1 = __webpack_require__(24898);
  1824. const get_vuln_url_1 = __webpack_require__(41438);
  1825. function formatIssuesWithRemediation(vulns, remediationInfo, options) {
  1826. const basicVulnInfo = {};
  1827. const basicLicenseInfo = {};
  1828. for (const vuln of vulns) {
  1829. const vulnData = {
  1830. title: vuln.title,
  1831. severity: vuln.severity,
  1832. originalSeverity: vuln.originalSeverity,
  1833. isNew: vuln.isNew,
  1834. name: vuln.name,
  1835. type: vuln.metadata.type,
  1836. version: vuln.version,
  1837. fixedIn: vuln.fixedIn,
  1838. note: vuln.note,
  1839. legalInstructions: vuln.legalInstructionsArray,
  1840. paths: vuln.list.map((v) => v.from),
  1841. };
  1842. if (vulnData.type === 'license') {
  1843. basicLicenseInfo[vuln.metadata.id] = vulnData;
  1844. }
  1845. else {
  1846. basicVulnInfo[vuln.metadata.id] = vulnData;
  1847. }
  1848. }
  1849. const results = [''];
  1850. let upgradeTextArray;
  1851. if (remediationInfo.pin && Object.keys(remediationInfo.pin).length) {
  1852. const upgradesByAffected = {};
  1853. for (const topLevelPkg of Object.keys(remediationInfo.upgrade)) {
  1854. for (const targetPkgStr of remediationInfo.upgrade[topLevelPkg]
  1855. .upgrades) {
  1856. if (!upgradesByAffected[targetPkgStr]) {
  1857. upgradesByAffected[targetPkgStr] = [];
  1858. }
  1859. upgradesByAffected[targetPkgStr].push({
  1860. name: topLevelPkg,
  1861. version: remediationInfo.upgrade[topLevelPkg].upgradeTo,
  1862. });
  1863. }
  1864. }
  1865. upgradeTextArray = constructPinText(remediationInfo.pin, upgradesByAffected, basicVulnInfo, options);
  1866. const allVulnIds = new Set();
  1867. Object.keys(remediationInfo.pin).forEach((name) => remediationInfo.pin[name].vulns.forEach((vid) => allVulnIds.add(vid)));
  1868. remediationInfo.unresolved = remediationInfo.unresolved.filter((issue) => !allVulnIds.has(issue.id));
  1869. }
  1870. else {
  1871. upgradeTextArray = constructUpgradesText(remediationInfo.upgrade, basicVulnInfo, options);
  1872. }
  1873. if (upgradeTextArray.length > 0) {
  1874. results.push(upgradeTextArray.join('\n'));
  1875. }
  1876. const patchedTextArray = constructPatchesText(remediationInfo.patch, basicVulnInfo, options);
  1877. if (patchedTextArray.length > 0) {
  1878. results.push(patchedTextArray.join('\n'));
  1879. }
  1880. const unfixableIssuesTextArray = constructUnfixableText(remediationInfo.unresolved, basicVulnInfo, options);
  1881. if (unfixableIssuesTextArray.length > 0) {
  1882. results.push(unfixableIssuesTextArray.join('\n'));
  1883. }
  1884. const licenseIssuesTextArray = constructLicenseText(basicLicenseInfo, options);
  1885. if (licenseIssuesTextArray.length > 0) {
  1886. results.push(licenseIssuesTextArray.join('\n'));
  1887. }
  1888. return results;
  1889. }
  1890. exports.formatIssuesWithRemediation = formatIssuesWithRemediation;
  1891. function constructLicenseText(basicLicenseInfo, testOptions) {
  1892. if (!(Object.keys(basicLicenseInfo).length > 0)) {
  1893. return [];
  1894. }
  1895. const licenseTextArray = [chalk_1.default.bold.green('\nLicense issues:')];
  1896. for (const id of Object.keys(basicLicenseInfo)) {
  1897. const licenseText = formatIssue(id, basicLicenseInfo[id].title, basicLicenseInfo[id].severity, basicLicenseInfo[id].isNew, `${basicLicenseInfo[id].name}@${basicLicenseInfo[id].version}`, basicLicenseInfo[id].paths, testOptions, basicLicenseInfo[id].note, undefined, // We can never override license rules, so no originalSeverity here
  1898. basicLicenseInfo[id].legalInstructions);
  1899. licenseTextArray.push('\n' + licenseText);
  1900. }
  1901. return licenseTextArray;
  1902. }
  1903. function constructPatchesText(patches, basicVulnInfo, testOptions) {
  1904. if (!(Object.keys(patches).length > 0)) {
  1905. return [];
  1906. }
  1907. const patchedTextArray = [chalk_1.default.bold.green('\nPatchable issues:')];
  1908. for (const id of Object.keys(patches)) {
  1909. if (!basicVulnInfo[id]) {
  1910. continue;
  1911. }
  1912. if (basicVulnInfo[id].type === 'license') {
  1913. continue;
  1914. }
  1915. // todo: add vulnToPatch package name
  1916. const packageAtVersion = `${basicVulnInfo[id].name}@${basicVulnInfo[id].version}`;
  1917. const patchedText = `\n Patch available for ${chalk_1.default.bold.whiteBright(packageAtVersion)}\n`;
  1918. const thisPatchFixes = formatIssue(id, basicVulnInfo[id].title, basicVulnInfo[id].severity, basicVulnInfo[id].isNew, `${basicVulnInfo[id].name}@${basicVulnInfo[id].version}`, basicVulnInfo[id].paths, testOptions, basicVulnInfo[id].note, basicVulnInfo[id].originalSeverity);
  1919. patchedTextArray.push(patchedText + thisPatchFixes);
  1920. }
  1921. return patchedTextArray;
  1922. }
  1923. function thisUpgradeFixes(vulnIds, basicVulnInfo, testOptions) {
  1924. return vulnIds
  1925. .filter((id) => basicVulnInfo[id]) // basicVulnInfo only contains issues with the specified severity levels
  1926. .sort((a, b) => get_severity_value_1.getSeverityValue(basicVulnInfo[a].severity) -
  1927. get_severity_value_1.getSeverityValue(basicVulnInfo[b].severity))
  1928. .filter((id) => basicVulnInfo[id].type !== 'license')
  1929. .map((id) => formatIssue(id, basicVulnInfo[id].title, basicVulnInfo[id].severity, basicVulnInfo[id].isNew, `${basicVulnInfo[id].name}@${basicVulnInfo[id].version}`, basicVulnInfo[id].paths, testOptions, basicVulnInfo[id].note, basicVulnInfo[id].originalSeverity, []))
  1930. .join('\n');
  1931. }
  1932. function processUpgrades(sink, upgradesByDep, deps, basicVulnInfo, testOptions) {
  1933. for (const dep of deps) {
  1934. const data = upgradesByDep[dep];
  1935. const upgradeDepTo = data.upgradeTo;
  1936. const vulnIds = data.vulns || data.vulns;
  1937. const upgradeText = `\n Upgrade ${chalk_1.default.bold.whiteBright(dep)} to ${chalk_1.default.bold.whiteBright(upgradeDepTo)} to fix\n`;
  1938. sink.push(upgradeText + thisUpgradeFixes(vulnIds, basicVulnInfo, testOptions));
  1939. }
  1940. }
  1941. function constructUpgradesText(upgrades, basicVulnInfo, testOptions) {
  1942. if (!(Object.keys(upgrades).length > 0)) {
  1943. return [];
  1944. }
  1945. const upgradeTextArray = [chalk_1.default.bold.green('\nIssues to fix by upgrading:')];
  1946. processUpgrades(upgradeTextArray, upgrades, Object.keys(upgrades), basicVulnInfo, testOptions);
  1947. return upgradeTextArray;
  1948. }
  1949. function constructPinText(pins, upgradesByAffected, // classical "remediation via top-level dep" upgrades
  1950. basicVulnInfo, testOptions) {
  1951. if (!Object.keys(pins).length) {
  1952. return [];
  1953. }
  1954. const upgradeTextArray = [];
  1955. upgradeTextArray.push(chalk_1.default.bold.green('\nIssues to fix by upgrading dependencies:'));
  1956. // First, direct upgrades
  1957. const upgradeables = Object.keys(pins).filter((name) => !pins[name].isTransitive);
  1958. if (upgradeables.length) {
  1959. processUpgrades(upgradeTextArray, pins, upgradeables, basicVulnInfo, testOptions);
  1960. }
  1961. // Second, pins
  1962. const pinables = Object.keys(pins).filter((name) => pins[name].isTransitive);
  1963. if (pinables.length) {
  1964. for (const pkgName of pinables) {
  1965. const data = pins[pkgName];
  1966. const vulnIds = data.vulns;
  1967. const upgradeDepTo = data.upgradeTo;
  1968. const upgradeText = `\n Pin ${chalk_1.default.bold.whiteBright(pkgName)} to ${chalk_1.default.bold.whiteBright(upgradeDepTo)} to fix`;
  1969. upgradeTextArray.push(upgradeText);
  1970. upgradeTextArray.push(thisUpgradeFixes(vulnIds, basicVulnInfo, testOptions));
  1971. // Finally, if we have some upgrade paths that fix the same issues, suggest them as well.
  1972. const topLevelUpgradesAlreadySuggested = new Set();
  1973. for (const vid of vulnIds) {
  1974. for (const topLevelPkg of upgradesByAffected[pkgName + '@' + basicVulnInfo[vid].version] || []) {
  1975. const setKey = `${topLevelPkg.name}\n${topLevelPkg.version}`;
  1976. if (!topLevelUpgradesAlreadySuggested.has(setKey)) {
  1977. topLevelUpgradesAlreadySuggested.add(setKey);
  1978. upgradeTextArray.push(' The issues above can also be fixed by upgrading top-level dependency ' +
  1979. `${topLevelPkg.name} to ${topLevelPkg.version}`);
  1980. }
  1981. }
  1982. }
  1983. }
  1984. }
  1985. return upgradeTextArray;
  1986. }
  1987. function constructUnfixableText(unresolved, basicVulnInfo, testOptions) {
  1988. if (!(unresolved.length > 0)) {
  1989. return [];
  1990. }
  1991. const unfixableIssuesTextArray = [
  1992. chalk_1.default.bold.white('\nIssues with no direct upgrade or patch:'),
  1993. ];
  1994. for (const issue of unresolved) {
  1995. const issueInfo = basicVulnInfo[issue.id];
  1996. if (!issueInfo) {
  1997. // basicVulnInfo only contains issues with the specified severity levels
  1998. continue;
  1999. }
  2000. const extraInfo = issue.fixedIn && issue.fixedIn.length
  2001. ? `\n This issue was fixed in versions: ${chalk_1.default.bold(issue.fixedIn.join(', '))}`
  2002. : '\n No upgrade or patch available';
  2003. unfixableIssuesTextArray.push(formatIssue(issue.id, issue.title, issue.severity, issue.isNew, `${issue.packageName}@${issue.version}`, issueInfo.paths, testOptions, issueInfo.note, issueInfo.originalSeverity, []) + `${extraInfo}`);
  2004. }
  2005. if (unfixableIssuesTextArray.length === 1) {
  2006. // seems we still only have
  2007. // the initial section title, so nothing to return
  2008. return [];
  2009. }
  2010. return unfixableIssuesTextArray;
  2011. }
  2012. function printPath(path, slice = 1) {
  2013. return path.slice(slice).join(constants_1.PATH_SEPARATOR);
  2014. }
  2015. exports.printPath = printPath;
  2016. function formatIssue(id, title, severity, isNew, vulnerableModule, paths, testOptions, note, originalSeverity, legalInstructions) {
  2017. const newBadge = isNew ? ' (new)' : '';
  2018. const name = vulnerableModule ? ` in ${chalk_1.default.bold(vulnerableModule)}` : '';
  2019. let legalLicenseInstructionsText;
  2020. if (legalInstructions) {
  2021. legalLicenseInstructionsText = legal_license_instructions_1.formatLegalInstructions(legalInstructions);
  2022. }
  2023. let introducedBy = '';
  2024. if (testOptions.showVulnPaths === 'some' &&
  2025. paths &&
  2026. paths.find((p) => p.length > 1)) {
  2027. // In this mode, we show only one path by default, for compactness
  2028. const pathStr = printPath(paths[0]);
  2029. introducedBy =
  2030. paths.length === 1
  2031. ? `\n introduced by ${pathStr}`
  2032. : `\n introduced by ${pathStr} and ${chalk_1.default.cyanBright('' + (paths.length - 1))} other path(s)`;
  2033. }
  2034. else if (testOptions.showVulnPaths === 'all' && paths) {
  2035. introducedBy =
  2036. '\n introduced by:' +
  2037. paths
  2038. .slice(0, 1000)
  2039. .map((p) => '\n ' + printPath(p))
  2040. .join('');
  2041. if (paths.length > 1000) {
  2042. introducedBy += `\n and ${chalk_1.default.cyanBright('' + (paths.length - 1))} other path(s)`;
  2043. }
  2044. }
  2045. let originalSeverityStr = '';
  2046. if (originalSeverity && originalSeverity !== severity) {
  2047. originalSeverityStr = ` (originally ${titleCaseText(originalSeverity)})`;
  2048. }
  2049. return (common_1.colorTextBySeverity(severity, ` ${theme_1.icon.ISSUE} ${chalk_1.default.bold(title)}${newBadge} [${titleCaseText(severity)} Severity${originalSeverityStr}]`) +
  2050. `[${get_vuln_url_1.getVulnerabilityUrl(id)}]` +
  2051. name +
  2052. introducedBy +
  2053. (legalLicenseInstructionsText
  2054. ? `${chalk_1.default.bold('\n Legal instructions')}:\n ${legalLicenseInstructionsText}`
  2055. : '') +
  2056. (note ? `${chalk_1.default.bold('\n Note')}:\n ${note}` : ''));
  2057. }
  2058. exports.formatIssue = formatIssue;
  2059. function titleCaseText(text) {
  2060. return text[0].toUpperCase() + text.slice(1);
  2061. }
  2062. /***/ }),
  2063. /***/ 98202:
  2064. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  2065. "use strict";
  2066. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2067. exports.showAllProjectsTip = void 0;
  2068. const is_multi_project_scan_1 = __webpack_require__(62435);
  2069. function showAllProjectsTip(packageManager, options, foundProjectCount) {
  2070. if (packageManager === 'gradle' ||
  2071. !foundProjectCount ||
  2072. is_multi_project_scan_1.isMultiProjectScan(options)) {
  2073. return '';
  2074. }
  2075. return (`Tip: Detected multiple supported manifests (${foundProjectCount}), ` +
  2076. 'use --all-projects to scan all of them at once.');
  2077. }
  2078. exports.showAllProjectsTip = showAllProjectsTip;
  2079. /***/ }),
  2080. /***/ 9658:
  2081. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  2082. "use strict";
  2083. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2084. exports.showGradleSubProjectsTip = void 0;
  2085. const is_multi_project_scan_1 = __webpack_require__(62435);
  2086. function showGradleSubProjectsTip(packageManager, options, foundProjectCount) {
  2087. if (packageManager !== 'gradle' ||
  2088. !foundProjectCount ||
  2089. is_multi_project_scan_1.isMultiProjectScan(options) ||
  2090. options.allSubProjects) {
  2091. return '';
  2092. }
  2093. return (`Tip: This project has multiple sub-projects (${foundProjectCount}), ` +
  2094. 'use --all-sub-projects flag to scan all sub-projects.');
  2095. }
  2096. exports.showGradleSubProjectsTip = showGradleSubProjectsTip;
  2097. /***/ }),
  2098. /***/ 95100:
  2099. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  2100. "use strict";
  2101. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2102. exports.showMultiScanTip = void 0;
  2103. const show_all_projects_tip_1 = __webpack_require__(98202);
  2104. const show_all_sub_projects_tip_1 = __webpack_require__(9658);
  2105. function showMultiScanTip(projectType, options, foundProjectCount) {
  2106. const gradleSubProjectsTip = show_all_sub_projects_tip_1.showGradleSubProjectsTip(projectType, options, foundProjectCount);
  2107. if (gradleSubProjectsTip) {
  2108. return gradleSubProjectsTip;
  2109. }
  2110. if (projectType === 'maven' &&
  2111. foundProjectCount &&
  2112. foundProjectCount > 1 &&
  2113. !options.allProjects &&
  2114. !options.mavenAggregateProject) {
  2115. return ('Tip: Detected Maven project, are you using modules? ' +
  2116. 'Use --maven-aggregate-project to scan each project. ' +
  2117. 'Alternatively use --all-projects to scan Maven and other types of projects.');
  2118. }
  2119. const allProjectsTip = show_all_projects_tip_1.showAllProjectsTip(projectType, options, foundProjectCount);
  2120. if (allProjectsTip) {
  2121. return allProjectsTip;
  2122. }
  2123. return '';
  2124. }
  2125. exports.showMultiScanTip = showMultiScanTip;
  2126. /***/ }),
  2127. /***/ 84210:
  2128. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  2129. "use strict";
  2130. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2131. exports.getFileContents = void 0;
  2132. const fs = __webpack_require__(35747);
  2133. const path = __webpack_require__(85622);
  2134. function getFileContents(root, fileName) {
  2135. const fullPath = path.resolve(root, fileName);
  2136. if (!fs.existsSync(fullPath)) {
  2137. throw new Error('Manifest ' + fileName + ' not found at location: ' + fileName);
  2138. }
  2139. const content = fs.readFileSync(fullPath, 'utf-8');
  2140. return {
  2141. content,
  2142. fileName,
  2143. };
  2144. }
  2145. exports.getFileContents = getFileContents;
  2146. /***/ }),
  2147. /***/ 62435:
  2148. /***/ ((__unused_webpack_module, exports) => {
  2149. "use strict";
  2150. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2151. exports.isMultiProjectScan = void 0;
  2152. function isMultiProjectScan(options) {
  2153. return !!(options.allProjects || options.yarnWorkspaces);
  2154. }
  2155. exports.isMultiProjectScan = isMultiProjectScan;
  2156. /***/ }),
  2157. /***/ 27019:
  2158. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  2159. "use strict";
  2160. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2161. exports.jsonStringifyLargeObject = void 0;
  2162. const debug = __webpack_require__(15158)('snyk-json');
  2163. /**
  2164. * Attempt to json-stringify an object which is potentially very large and might exceed the string limit.
  2165. * If it does exceed the string limit, try again without pretty-print to hopefully come out below the string limit.
  2166. * @param obj the object from which you want to get a JSON string
  2167. */
  2168. function jsonStringifyLargeObject(obj) {
  2169. let res = '';
  2170. try {
  2171. // first try pretty-print
  2172. res = JSON.stringify(obj, null, 2);
  2173. return res;
  2174. }
  2175. catch (err) {
  2176. // if that doesn't work, try non-pretty print
  2177. debug('JSON.stringify failed - trying again without pretty print', err);
  2178. res = JSON.stringify(obj);
  2179. return res;
  2180. }
  2181. }
  2182. exports.jsonStringifyLargeObject = jsonStringifyLargeObject;
  2183. /***/ }),
  2184. /***/ 80777:
  2185. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  2186. "use strict";
  2187. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2188. exports.ModuleInfo = void 0;
  2189. const merge = __webpack_require__(72378);
  2190. const Debug = __webpack_require__(15158);
  2191. const debug = Debug('snyk-module-info');
  2192. function ModuleInfo(plugin, policy) {
  2193. return {
  2194. async inspect(root, targetFile, options) {
  2195. const pluginOptions = merge({
  2196. args: options._doubleDashArgs,
  2197. }, options);
  2198. debug('calling plugin inspect()', { root, targetFile, pluginOptions });
  2199. const info = await plugin.inspect(root, targetFile, pluginOptions);
  2200. debug('plugin inspect() done');
  2201. // attach policy if not provided by plugin
  2202. if (policy && !info.package.policy) {
  2203. info.package.policy = policy.toString();
  2204. }
  2205. return info;
  2206. },
  2207. };
  2208. }
  2209. exports.ModuleInfo = ModuleInfo;
  2210. /***/ }),
  2211. /***/ 61900:
  2212. /***/ ((__unused_webpack_module, exports) => {
  2213. "use strict";
  2214. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2215. exports.countTotalDependenciesInTree = void 0;
  2216. function countTotalDependenciesInTree(depTree) {
  2217. let count = 0;
  2218. if (depTree.dependencies) {
  2219. for (const name of Object.keys(depTree.dependencies)) {
  2220. const dep = depTree.dependencies[name];
  2221. if (dep) {
  2222. count += 1 + countTotalDependenciesInTree(dep);
  2223. }
  2224. }
  2225. }
  2226. return count;
  2227. }
  2228. exports.countTotalDependenciesInTree = countTotalDependenciesInTree;
  2229. /***/ }),
  2230. /***/ 73898:
  2231. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  2232. "use strict";
  2233. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2234. exports.ShellOutError = exports.execShell = exports.separateLines = exports.runGitLog = exports.getTimestampStartOfContributingDevTimeframe = exports.parseGitLog = exports.parseGitLogLine = exports.GitRepoCommitStats = exports.GitCommitInfo = exports.getContributors = exports.MAX_COMMITS_IN_GIT_LOG = exports.CONTRIBUTING_DEVELOPER_PERIOD_DAYS = exports.SERIOUS_DELIMITER = void 0;
  2235. /**
  2236. * This is to count the number of "contributing" developers using Snyk on a given repo.
  2237. * "Contributing" is defined as having contributed a commit in the last 90 days.
  2238. * This is use only on the `snyk monitor` command as that is used to monitor a project's dependencies in an
  2239. * on-going manner.
  2240. * It collects the email of a git user and the most recent commit timestamp (both per the `git log`
  2241. * output) and can be disabled by config (see https://snyk.io/policies/tracking-and-analytics/).
  2242. */
  2243. const child_process_1 = __webpack_require__(63129);
  2244. exports.SERIOUS_DELIMITER = '_SNYK_SEPARATOR_';
  2245. exports.CONTRIBUTING_DEVELOPER_PERIOD_DAYS = 90;
  2246. // Limit the number of commits returned from `git log` command to stay within maxBuffer limit
  2247. exports.MAX_COMMITS_IN_GIT_LOG = 500;
  2248. async function getContributors({ endDate, periodDays, repoPath } = {
  2249. endDate: new Date(),
  2250. periodDays: exports.CONTRIBUTING_DEVELOPER_PERIOD_DAYS,
  2251. repoPath: process.cwd(),
  2252. }) {
  2253. const timestampStartOfContributingDeveloperPeriod = getTimestampStartOfContributingDevTimeframe(endDate, periodDays);
  2254. const gitLogResults = await runGitLog(timestampStartOfContributingDeveloperPeriod, Math.floor(endDate.getTime() / 1000), repoPath, execShell);
  2255. const stats = parseGitLog(gitLogResults);
  2256. return stats.getRepoContributors();
  2257. }
  2258. exports.getContributors = getContributors;
  2259. class GitCommitInfo {
  2260. constructor(authorEmail, commitTimestamp) {
  2261. this.authorEmail = authorEmail;
  2262. this.commitTimestamp = commitTimestamp;
  2263. }
  2264. }
  2265. exports.GitCommitInfo = GitCommitInfo;
  2266. class GitRepoCommitStats {
  2267. constructor(commitInfos) {
  2268. this.commitInfos = commitInfos;
  2269. }
  2270. static empty() {
  2271. return new GitRepoCommitStats([]);
  2272. }
  2273. addCommitInfo(info) {
  2274. this.commitInfos.push(info);
  2275. }
  2276. getUniqueAuthorsCount() {
  2277. const uniqueAuthorEmails = this.getUniqueAuthorEmails();
  2278. return uniqueAuthorEmails.size;
  2279. }
  2280. getCommitsCount() {
  2281. return this.commitInfos.length;
  2282. }
  2283. getUniqueAuthorEmails() {
  2284. const allCommitAuthorHashedEmails = this.commitInfos.map((c) => c.authorEmail);
  2285. const uniqueAuthorEmails = new Set(allCommitAuthorHashedEmails);
  2286. return uniqueAuthorEmails;
  2287. }
  2288. getRepoContributors() {
  2289. const uniqueAuthorEmails = this.getUniqueAuthorEmails();
  2290. const contributors = [];
  2291. for (const nextUniqueAuthorEmail of uniqueAuthorEmails) {
  2292. const latestCommitTimestamp = this.getMostRecentCommitTimestamp(nextUniqueAuthorEmail);
  2293. contributors.push({
  2294. email: nextUniqueAuthorEmail,
  2295. lastCommitDate: latestCommitTimestamp,
  2296. });
  2297. }
  2298. return contributors;
  2299. }
  2300. getMostRecentCommitTimestamp(authorHashedEmail) {
  2301. for (const nextGI of this.commitInfos) {
  2302. if (nextGI.authorEmail === authorHashedEmail) {
  2303. return nextGI.commitTimestamp;
  2304. }
  2305. }
  2306. return '';
  2307. }
  2308. }
  2309. exports.GitRepoCommitStats = GitRepoCommitStats;
  2310. function parseGitLogLine(logLine) {
  2311. const lineComponents = logLine.split(exports.SERIOUS_DELIMITER);
  2312. const authorEmail = lineComponents[2];
  2313. const commitTimestamp = lineComponents[3];
  2314. const commitInfo = new GitCommitInfo(authorEmail, commitTimestamp);
  2315. return commitInfo;
  2316. }
  2317. exports.parseGitLogLine = parseGitLogLine;
  2318. function parseGitLog(gitLog) {
  2319. if (gitLog.trim() === '') {
  2320. return GitRepoCommitStats.empty();
  2321. }
  2322. const logLines = separateLines(gitLog);
  2323. const logLineInfos = logLines.map(parseGitLogLine);
  2324. const stats = new GitRepoCommitStats(logLineInfos);
  2325. return stats;
  2326. }
  2327. exports.parseGitLog = parseGitLog;
  2328. /**
  2329. * @returns time stamp in seconds-since-epoch of 90 days ago since 90 days is the "contributing devs" timeframe
  2330. */
  2331. function getTimestampStartOfContributingDevTimeframe(dNow, timespanInDays = exports.CONTRIBUTING_DEVELOPER_PERIOD_DAYS) {
  2332. const nowUtcEpocMS = dNow.getTime();
  2333. const nowUtcEpocS = Math.floor(nowUtcEpocMS / 1000);
  2334. const ONE_DAY_IN_SECONDS = 86400;
  2335. const lookbackTimespanSeconds = timespanInDays * ONE_DAY_IN_SECONDS;
  2336. const startOfPeriodEpochSeconds = nowUtcEpocS - lookbackTimespanSeconds;
  2337. return startOfPeriodEpochSeconds;
  2338. }
  2339. exports.getTimestampStartOfContributingDevTimeframe = getTimestampStartOfContributingDevTimeframe;
  2340. async function runGitLog(timestampEpochSecondsStartOfPeriod, timestampEpochSecondsEndOfPeriod, repoPath, fnShellout) {
  2341. try {
  2342. const gitLogCommand = `git --no-pager log --pretty=tformat:"%H${exports.SERIOUS_DELIMITER}%an${exports.SERIOUS_DELIMITER}%ae${exports.SERIOUS_DELIMITER}%aI" --after="${timestampEpochSecondsStartOfPeriod}" --until="${timestampEpochSecondsEndOfPeriod}" --max-count=${exports.MAX_COMMITS_IN_GIT_LOG}`;
  2343. const gitLogStdout = await fnShellout(gitLogCommand, repoPath);
  2344. return gitLogStdout;
  2345. }
  2346. catch {
  2347. return '';
  2348. }
  2349. }
  2350. exports.runGitLog = runGitLog;
  2351. function separateLines(inputText) {
  2352. const linuxStyleNewLine = '\n';
  2353. const windowsStyleNewLine = '\r\n';
  2354. const reg = new RegExp(`${linuxStyleNewLine}|${windowsStyleNewLine}`);
  2355. const lines = inputText.trim().split(reg);
  2356. return lines;
  2357. }
  2358. exports.separateLines = separateLines;
  2359. function execShell(cmd, workingDirectory) {
  2360. const options = {
  2361. cwd: workingDirectory,
  2362. };
  2363. return new Promise((resolve, reject) => {
  2364. child_process_1.exec(cmd, options, (error, stdout, stderr) => {
  2365. if (error) {
  2366. const exitCode = error.code;
  2367. const e = new ShellOutError(error.message, exitCode, stdout, stderr, error);
  2368. reject(e);
  2369. }
  2370. else {
  2371. resolve(stdout ? stdout : stderr);
  2372. }
  2373. });
  2374. });
  2375. }
  2376. exports.execShell = execShell;
  2377. class ShellOutError extends Error {
  2378. constructor(message, exitCode, stdout, stderr, innerError) {
  2379. super(message);
  2380. this.exitCode = exitCode;
  2381. this.stdout = stdout;
  2382. this.stderr = stderr;
  2383. this.innerError = innerError;
  2384. }
  2385. }
  2386. exports.ShellOutError = ShellOutError;
  2387. /***/ }),
  2388. /***/ 55916:
  2389. /***/ ((__unused_webpack_module, exports) => {
  2390. "use strict";
  2391. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2392. exports.dropEmptyDeps = void 0;
  2393. function dropEmptyDeps(depTree) {
  2394. if (depTree.dependencies) {
  2395. const keys = Object.keys(depTree.dependencies);
  2396. if (keys.length === 0) {
  2397. delete depTree.dependencies;
  2398. }
  2399. else {
  2400. for (const k of keys) {
  2401. dropEmptyDeps(depTree.dependencies[k]);
  2402. }
  2403. }
  2404. }
  2405. return depTree;
  2406. }
  2407. exports.dropEmptyDeps = dropEmptyDeps;
  2408. /***/ }),
  2409. /***/ 85768:
  2410. /***/ ((__unused_webpack_module, exports) => {
  2411. "use strict";
  2412. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2413. exports.filterOutMissingDeps = void 0;
  2414. function filterOutMissingDeps(depTree) {
  2415. const filteredDeps = {};
  2416. const missingDeps = [];
  2417. if (!depTree.dependencies) {
  2418. return {
  2419. filteredDepTree: depTree,
  2420. missingDeps,
  2421. };
  2422. }
  2423. for (const depKey of Object.keys(depTree.dependencies)) {
  2424. const dep = depTree.dependencies[depKey];
  2425. if (dep.missingLockFileEntry ||
  2426. (dep.labels && dep.labels.missingLockFileEntry)) {
  2427. // TODO(kyegupov): add field to the type
  2428. missingDeps.push(`${dep.name}@${dep.version}`);
  2429. }
  2430. else {
  2431. filteredDeps[depKey] = dep;
  2432. }
  2433. }
  2434. const filteredDepTree = {
  2435. ...depTree,
  2436. dependencies: filteredDeps,
  2437. };
  2438. return {
  2439. filteredDepTree,
  2440. missingDeps,
  2441. };
  2442. }
  2443. exports.filterOutMissingDeps = filterOutMissingDeps;
  2444. /***/ }),
  2445. /***/ 3959:
  2446. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  2447. "use strict";
  2448. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2449. exports.monitorDepGraph = exports.monitor = void 0;
  2450. const Debug = __webpack_require__(15158);
  2451. const path = __webpack_require__(85622);
  2452. const depGraphLib = __webpack_require__(71479);
  2453. const snyk = __webpack_require__(9146);
  2454. const api_token_1 = __webpack_require__(95181);
  2455. const request_1 = __webpack_require__(52050);
  2456. const config_1 = __webpack_require__(25425);
  2457. const os = __webpack_require__(12087);
  2458. const is_ci_1 = __webpack_require__(10090);
  2459. const analytics = __webpack_require__(82744);
  2460. const projectMetadata = __webpack_require__(3594);
  2461. const errors_1 = __webpack_require__(55191);
  2462. const prune_1 = __webpack_require__(87725);
  2463. const package_managers_1 = __webpack_require__(53847);
  2464. const count_total_deps_in_tree_1 = __webpack_require__(61900);
  2465. const filter_out_missing_deps_1 = __webpack_require__(85768);
  2466. const drop_empty_deps_1 = __webpack_require__(55916);
  2467. const prune_dep_tree_1 = __webpack_require__(35797);
  2468. const policy_1 = __webpack_require__(32615);
  2469. const types_1 = __webpack_require__(39409);
  2470. const utils_1 = __webpack_require__(49530);
  2471. const utils_2 = __webpack_require__(61721);
  2472. const debug = Debug('snyk');
  2473. async function monitor(root, meta, scannedProject, options, pluginMeta, targetFileRelativePath, contributors, projectAttributes, tags) {
  2474. api_token_1.apiOrOAuthTokenExists();
  2475. const packageManager = meta.packageManager;
  2476. analytics.add('packageManager', packageManager);
  2477. analytics.add('isDocker', !!meta.isDocker);
  2478. if (scannedProject.depGraph) {
  2479. return await monitorDepGraph(root, meta, scannedProject, pluginMeta, options, targetFileRelativePath, contributors, projectAttributes, tags);
  2480. }
  2481. if (package_managers_1.GRAPH_SUPPORTED_PACKAGE_MANAGERS.includes(packageManager)) {
  2482. return await monitorDepGraphFromDepTree(root, meta, scannedProject, pluginMeta, options, targetFileRelativePath, contributors, projectAttributes, tags);
  2483. }
  2484. return await monitorDepTree(root, meta, scannedProject, pluginMeta, options, targetFileRelativePath, contributors, projectAttributes, tags);
  2485. }
  2486. exports.monitor = monitor;
  2487. async function monitorDepTree(root, meta, scannedProject, pluginMeta, options, targetFileRelativePath, contributors, projectAttributes, tags) {
  2488. var _a, _b, _c;
  2489. let treeMissingDeps = [];
  2490. const packageManager = meta.packageManager;
  2491. let depTree = scannedProject.depTree;
  2492. if (!depTree) {
  2493. debug('scannedProject is missing depGraph or depTree, cannot run test/monitor');
  2494. throw new errors_1.FailedToRunTestError(errors_1.errorMessageWithRetry('Your monitor request could not be completed.'));
  2495. }
  2496. let prePruneDepCount;
  2497. if (meta.prune) {
  2498. debug('prune used, counting total dependencies');
  2499. prePruneDepCount = count_total_deps_in_tree_1.countTotalDependenciesInTree(depTree);
  2500. analytics.add('prePruneDepCount', prePruneDepCount);
  2501. debug('total dependencies: %d', prePruneDepCount);
  2502. debug('pruning dep tree');
  2503. depTree = await prune_dep_tree_1.pruneTree(depTree, meta.packageManager);
  2504. debug('finished pruning dep tree');
  2505. }
  2506. if (['npm', 'yarn'].includes(meta.packageManager)) {
  2507. const { filteredDepTree, missingDeps } = filter_out_missing_deps_1.filterOutMissingDeps(depTree);
  2508. depTree = filteredDepTree;
  2509. treeMissingDeps = missingDeps;
  2510. }
  2511. let targetFileDir;
  2512. if (targetFileRelativePath) {
  2513. const { dir } = path.parse(targetFileRelativePath);
  2514. targetFileDir = dir;
  2515. }
  2516. const policy = await policy_1.findAndLoadPolicy(root, meta.isDocker ? 'docker' : packageManager, options, depTree, targetFileDir);
  2517. const target = await projectMetadata.getInfo(scannedProject, meta, depTree);
  2518. if (types_1.isGitTarget(target) && target.branch) {
  2519. analytics.add('targetBranch', target.branch);
  2520. }
  2521. depTree = drop_empty_deps_1.dropEmptyDeps(depTree);
  2522. let callGraphPayload;
  2523. if (!depTree) {
  2524. debug('scannedProject is missing depGraph or depTree, cannot run test/monitor');
  2525. throw new errors_1.FailedToRunTestError(errors_1.errorMessageWithRetry('Your monitor request could not be completed.'));
  2526. }
  2527. const { res, body } = await request_1.makeRequest({
  2528. body: {
  2529. meta: {
  2530. method: meta.method,
  2531. hostname: os.hostname(),
  2532. id: snyk.id || depTree.name,
  2533. ci: is_ci_1.isCI(),
  2534. pid: process.pid,
  2535. node: process.version,
  2536. master: snyk.config.isMaster,
  2537. name: utils_1.getNameDepTree(scannedProject, depTree, meta),
  2538. version: depTree.version,
  2539. org: config_1.default.org ? decodeURIComponent(config_1.default.org) : undefined,
  2540. pluginName: pluginMeta.name,
  2541. pluginRuntime: pluginMeta.runtime,
  2542. missingDeps: treeMissingDeps,
  2543. dockerImageId: pluginMeta.dockerImageId,
  2544. dockerBaseImage: depTree.docker ? depTree.docker.baseImage : undefined,
  2545. dockerfileLayers: depTree.docker
  2546. ? depTree.docker.dockerfileLayers
  2547. : undefined,
  2548. projectName: utils_1.getProjectName(scannedProject, meta),
  2549. prePruneDepCount,
  2550. monitorGraph: false,
  2551. versionBuildInfo: JSON.stringify((_a = scannedProject.meta) === null || _a === void 0 ? void 0 : _a.versionBuildInfo),
  2552. gradleProjectName: (_b = scannedProject.meta) === null || _b === void 0 ? void 0 : _b.gradleProjectName,
  2553. platform: (_c = scannedProject.meta) === null || _c === void 0 ? void 0 : _c.platform,
  2554. },
  2555. policy: policy ? policy.toString() : undefined,
  2556. package: depTree,
  2557. callGraph: callGraphPayload,
  2558. // we take the targetFile from the plugin,
  2559. // because we want to send it only for specific package-managers
  2560. target,
  2561. // WARNING: be careful changing this as it affects project uniqueness
  2562. targetFile: utils_1.getTargetFile(scannedProject, pluginMeta),
  2563. targetFileRelativePath,
  2564. targetReference: meta.targetReference,
  2565. contributors,
  2566. projectAttributes,
  2567. tags,
  2568. },
  2569. gzip: true,
  2570. method: 'PUT',
  2571. headers: {
  2572. authorization: api_token_1.getAuthHeader(),
  2573. 'content-encoding': 'gzip',
  2574. },
  2575. url: config_1.default.API + '/monitor/' + packageManager,
  2576. json: true,
  2577. });
  2578. if (res.statusCode && res.statusCode >= 200 && res.statusCode <= 299) {
  2579. return body;
  2580. }
  2581. else {
  2582. const userMessage = body && body.userMessage;
  2583. if (!userMessage && res.statusCode === 504) {
  2584. throw new errors_1.ConnectionTimeoutError();
  2585. }
  2586. else {
  2587. throw new errors_1.MonitorError(res.statusCode, userMessage);
  2588. }
  2589. }
  2590. }
  2591. async function monitorDepGraph(root, meta, scannedProject, pluginMeta, options, targetFileRelativePath, contributors, projectAttributes, tags) {
  2592. var _a, _b;
  2593. const packageManager = meta.packageManager;
  2594. analytics.add('monitorDepGraph', true);
  2595. let depGraph = scannedProject.depGraph;
  2596. if (!depGraph) {
  2597. debug('scannedProject is missing depGraph or depTree, cannot run test/monitor');
  2598. throw new errors_1.FailedToRunTestError('Your monitor request could not be completed. ');
  2599. }
  2600. let targetFileDir;
  2601. if (targetFileRelativePath) {
  2602. const { dir } = path.parse(targetFileRelativePath);
  2603. targetFileDir = dir;
  2604. }
  2605. const policy = await policy_1.findAndLoadPolicy(root, meta.isDocker ? 'docker' : packageManager, options, undefined, targetFileDir);
  2606. const target = await projectMetadata.getInfo(scannedProject, meta);
  2607. if (types_1.isGitTarget(target) && target.branch) {
  2608. analytics.add('targetBranch', target.branch);
  2609. }
  2610. const pruneIsRequired = options.pruneRepeatedSubdependencies;
  2611. depGraph = await prune_1.pruneGraph(depGraph, packageManager, pruneIsRequired);
  2612. let callGraphPayload;
  2613. if (!depGraph) {
  2614. debug('scannedProject is missing depGraph or depTree, cannot run test/monitor');
  2615. throw new errors_1.FailedToRunTestError(errors_1.errorMessageWithRetry('Your monitor request could not be completed.'));
  2616. }
  2617. const { res, body } = await request_1.makeRequest({
  2618. body: {
  2619. meta: {
  2620. method: meta.method,
  2621. hostname: os.hostname(),
  2622. id: snyk.id || depGraph.rootPkg.name,
  2623. ci: is_ci_1.isCI(),
  2624. pid: process.pid,
  2625. node: process.version,
  2626. master: snyk.config.isMaster,
  2627. name: utils_1.getNameDepGraph(scannedProject, depGraph, meta),
  2628. version: depGraph.rootPkg.version,
  2629. org: config_1.default.org ? decodeURIComponent(config_1.default.org) : undefined,
  2630. pluginName: pluginMeta.name,
  2631. pluginRuntime: pluginMeta.runtime,
  2632. projectName: utils_1.getProjectName(scannedProject, meta),
  2633. monitorGraph: true,
  2634. versionBuildInfo: JSON.stringify((_a = scannedProject.meta) === null || _a === void 0 ? void 0 : _a.versionBuildInfo),
  2635. gradleProjectName: (_b = scannedProject.meta) === null || _b === void 0 ? void 0 : _b.gradleProjectName,
  2636. },
  2637. policy: policy ? policy.toString() : undefined,
  2638. depGraphJSON: depGraph,
  2639. // we take the targetFile from the plugin,
  2640. // because we want to send it only for specific package-managers
  2641. target,
  2642. targetFile: utils_1.getTargetFile(scannedProject, pluginMeta),
  2643. targetFileRelativePath,
  2644. targetReference: meta.targetReference,
  2645. contributors,
  2646. callGraph: callGraphPayload,
  2647. projectAttributes,
  2648. tags,
  2649. },
  2650. gzip: true,
  2651. method: 'PUT',
  2652. headers: {
  2653. authorization: api_token_1.getAuthHeader(),
  2654. 'content-encoding': 'gzip',
  2655. },
  2656. url: `${config_1.default.API}/monitor/${packageManager}/graph`,
  2657. json: true,
  2658. });
  2659. if (res.statusCode && res.statusCode >= 200 && res.statusCode <= 299) {
  2660. return body;
  2661. }
  2662. else {
  2663. const userMessage = body && body.userMessage;
  2664. if (!userMessage && res.statusCode === 504) {
  2665. throw new errors_1.ConnectionTimeoutError();
  2666. }
  2667. else {
  2668. throw new errors_1.MonitorError(res.statusCode, userMessage);
  2669. }
  2670. }
  2671. }
  2672. exports.monitorDepGraph = monitorDepGraph;
  2673. async function monitorDepGraphFromDepTree(root, meta, scannedProject, pluginMeta, options, targetFileRelativePath, contributors, projectAttributes, tags) {
  2674. const packageManager = meta.packageManager;
  2675. let treeMissingDeps;
  2676. let depTree = scannedProject.depTree;
  2677. if (!depTree) {
  2678. debug('scannedProject is missing depGraph or depTree, cannot run test/monitor');
  2679. throw new errors_1.FailedToRunTestError(errors_1.errorMessageWithRetry('Your monitor request could not be completed'));
  2680. }
  2681. let targetFileDir;
  2682. if (targetFileRelativePath) {
  2683. const { dir } = path.parse(targetFileRelativePath);
  2684. targetFileDir = dir;
  2685. }
  2686. const policy = await policy_1.findAndLoadPolicy(root, meta.isDocker ? 'docker' : packageManager, options,
  2687. // TODO: fix this and send only send when we used resolve-deps for node
  2688. // it should be a ExpandedPkgTree type instead
  2689. depTree, targetFileDir);
  2690. if (['npm', 'yarn'].includes(meta.packageManager)) {
  2691. const { filteredDepTree, missingDeps } = filter_out_missing_deps_1.filterOutMissingDeps(depTree);
  2692. depTree = filteredDepTree;
  2693. treeMissingDeps = missingDeps;
  2694. }
  2695. const depGraph = await depGraphLib.legacy.depTreeToGraph(depTree, packageManager);
  2696. const target = await projectMetadata.getInfo(scannedProject, meta, depTree);
  2697. if (types_1.isGitTarget(target) && target.branch) {
  2698. analytics.add('targetBranch', target.branch);
  2699. }
  2700. let prunedGraph = depGraph;
  2701. let prePruneDepCount;
  2702. if (meta.prune) {
  2703. debug('Trying to prune the graph');
  2704. prePruneDepCount = utils_2.countPathsToGraphRoot(depGraph);
  2705. debug('pre prunedPathsCount: ' + prePruneDepCount);
  2706. prunedGraph = await prune_1.pruneGraph(depGraph, packageManager, meta.prune);
  2707. }
  2708. if (!depTree) {
  2709. debug('scannedProject is missing depGraph or depTree, cannot run test/monitor');
  2710. throw new errors_1.FailedToRunTestError(errors_1.errorMessageWithRetry('Your monitor request could not be completed.'));
  2711. }
  2712. const { res, body } = await request_1.makeRequest({
  2713. body: {
  2714. meta: {
  2715. method: meta.method,
  2716. hostname: os.hostname(),
  2717. id: snyk.id || depTree.name,
  2718. ci: is_ci_1.isCI(),
  2719. pid: process.pid,
  2720. node: process.version,
  2721. master: snyk.config.isMaster,
  2722. name: utils_1.getNameDepGraph(scannedProject, depGraph, meta),
  2723. version: depGraph.rootPkg.version,
  2724. org: config_1.default.org ? decodeURIComponent(config_1.default.org) : undefined,
  2725. pluginName: pluginMeta.name,
  2726. pluginRuntime: pluginMeta.runtime,
  2727. dockerImageId: pluginMeta.dockerImageId,
  2728. dockerBaseImage: depTree.docker ? depTree.docker.baseImage : undefined,
  2729. dockerfileLayers: depTree.docker
  2730. ? depTree.docker.dockerfileLayers
  2731. : undefined,
  2732. projectName: utils_1.getProjectName(scannedProject, meta),
  2733. prePruneDepCount,
  2734. missingDeps: treeMissingDeps,
  2735. monitorGraph: true,
  2736. },
  2737. policy: policy ? policy.toString() : undefined,
  2738. depGraphJSON: prunedGraph,
  2739. // we take the targetFile from the plugin,
  2740. // because we want to send it only for specific package-managers
  2741. target,
  2742. targetFile: utils_1.getTargetFile(scannedProject, pluginMeta),
  2743. targetFileRelativePath,
  2744. targetReference: meta.targetReference,
  2745. contributors,
  2746. projectAttributes,
  2747. tags,
  2748. },
  2749. gzip: true,
  2750. method: 'PUT',
  2751. headers: {
  2752. authorization: api_token_1.getAuthHeader(),
  2753. 'content-encoding': 'gzip',
  2754. },
  2755. url: `${config_1.default.API}/monitor/${packageManager}/graph`,
  2756. json: true,
  2757. });
  2758. if (res.statusCode && res.statusCode >= 200 && res.statusCode <= 299) {
  2759. return body;
  2760. }
  2761. else {
  2762. const userMessage = body && body.userMessage;
  2763. if (!userMessage && res.statusCode === 504) {
  2764. throw new errors_1.ConnectionTimeoutError();
  2765. }
  2766. else {
  2767. throw new errors_1.MonitorError(res.statusCode, userMessage);
  2768. }
  2769. }
  2770. }
  2771. /***/ }),
  2772. /***/ 35797:
  2773. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  2774. "use strict";
  2775. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2776. exports.pruneTree = void 0;
  2777. const depGraphLib = __webpack_require__(71479);
  2778. async function pruneTree(tree, packageManagerName) {
  2779. // Pruning requires conversion to the graph first.
  2780. // This is slow.
  2781. const graph = await depGraphLib.legacy.depTreeToGraph(tree, packageManagerName);
  2782. const prunedTree = (await depGraphLib.legacy.graphToDepTree(graph, packageManagerName, { deduplicateWithinTopLevelDeps: true }));
  2783. // Transplant pruned dependencies in the original tree (we want to keep all other fields):
  2784. tree.dependencies = prunedTree.dependencies;
  2785. return tree;
  2786. }
  2787. exports.pruneTree = pruneTree;
  2788. /***/ }),
  2789. /***/ 49530:
  2790. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  2791. "use strict";
  2792. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2793. exports.getTargetFile = exports.getProjectName = exports.getNameDepGraph = exports.getNameDepTree = void 0;
  2794. const container_1 = __webpack_require__(51804);
  2795. function getNameDepTree(scannedProject, depTree, meta) {
  2796. if (container_1.isContainer(scannedProject)) {
  2797. return container_1.getContainerName(scannedProject, meta);
  2798. }
  2799. return depTree.name;
  2800. }
  2801. exports.getNameDepTree = getNameDepTree;
  2802. function getNameDepGraph(scannedProject, depGraph, meta) {
  2803. var _a;
  2804. if (container_1.isContainer(scannedProject)) {
  2805. return container_1.getContainerName(scannedProject, meta);
  2806. }
  2807. return (_a = depGraph.rootPkg) === null || _a === void 0 ? void 0 : _a.name;
  2808. }
  2809. exports.getNameDepGraph = getNameDepGraph;
  2810. function getProjectName(scannedProject, meta) {
  2811. var _a;
  2812. if (container_1.isContainer(scannedProject)) {
  2813. return container_1.getContainerProjectName(scannedProject, meta);
  2814. }
  2815. if (meta['project-name'] && ((_a = scannedProject.meta) === null || _a === void 0 ? void 0 : _a.projectName)) {
  2816. return scannedProject.meta.projectName;
  2817. }
  2818. return meta['project-name'];
  2819. }
  2820. exports.getProjectName = getProjectName;
  2821. function getTargetFile(scannedProject, pluginMeta) {
  2822. if (container_1.isContainer(scannedProject)) {
  2823. return container_1.getContainerTargetFile(scannedProject);
  2824. }
  2825. return pluginMeta.targetFile;
  2826. }
  2827. exports.getTargetFile = getTargetFile;
  2828. /***/ }),
  2829. /***/ 23110:
  2830. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  2831. "use strict";
  2832. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2833. exports.convertMultiResultToMultiCustom = void 0;
  2834. const convert_scanned_projects_to_custom_1 = __webpack_require__(92909);
  2835. function convertMultiResultToMultiCustom(inspectRes, packageManager, targetFile) {
  2836. // convert all results from the same plugin to MultiProjectResultCustom
  2837. // and annotate each scannedProject with packageManager
  2838. return {
  2839. plugin: inspectRes.plugin,
  2840. scannedProjects: convert_scanned_projects_to_custom_1.convertScannedProjectsToCustom(inspectRes.scannedProjects, inspectRes.plugin, inspectRes.plugin.packageManager ||
  2841. packageManager, targetFile),
  2842. };
  2843. }
  2844. exports.convertMultiResultToMultiCustom = convertMultiResultToMultiCustom;
  2845. /***/ }),
  2846. /***/ 92909:
  2847. /***/ ((__unused_webpack_module, exports) => {
  2848. "use strict";
  2849. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2850. exports.convertScannedProjectsToCustom = void 0;
  2851. function convertScannedProjectsToCustom(scannedProjects, pluginMeta, packageManager, targetFile) {
  2852. // annotate the package manager & targetFile to be used
  2853. // for test & monitor
  2854. return scannedProjects.map((a) => {
  2855. a.plugin =
  2856. a.plugin || pluginMeta;
  2857. a.targetFile = a.targetFile || targetFile;
  2858. a.packageManager = a
  2859. .packageManager
  2860. ? a.packageManager
  2861. : packageManager;
  2862. a.meta = a.meta;
  2863. return a;
  2864. });
  2865. }
  2866. exports.convertScannedProjectsToCustom = convertScannedProjectsToCustom;
  2867. /***/ }),
  2868. /***/ 99695:
  2869. /***/ ((__unused_webpack_module, exports) => {
  2870. "use strict";
  2871. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2872. exports.convertSingleResultToMultiCustom = void 0;
  2873. function convertSingleResultToMultiCustom(inspectRes, packageManager) {
  2874. if (!packageManager) {
  2875. packageManager = inspectRes.plugin
  2876. .packageManager;
  2877. }
  2878. if (inspectRes.dependencyGraph) {
  2879. return convertDepGraphResult(inspectRes, packageManager);
  2880. }
  2881. else {
  2882. return convertDepTreeResult(inspectRes, packageManager);
  2883. }
  2884. }
  2885. exports.convertSingleResultToMultiCustom = convertSingleResultToMultiCustom;
  2886. function convertDepGraphResult(inspectRes, packageManager) {
  2887. const { plugin, meta, dependencyGraph: depGraph, callGraph } = inspectRes;
  2888. return {
  2889. plugin,
  2890. scannedProjects: [
  2891. {
  2892. plugin: plugin,
  2893. depGraph,
  2894. callGraph: callGraph,
  2895. meta,
  2896. targetFile: plugin.targetFile,
  2897. packageManager,
  2898. },
  2899. ],
  2900. };
  2901. }
  2902. /**
  2903. * @deprecated @boost: delete me when all languages uses depGraph
  2904. */
  2905. function convertDepTreeResult(inspectRes, packageManager) {
  2906. if (inspectRes.package &&
  2907. !inspectRes.package.targetFile &&
  2908. inspectRes.plugin) {
  2909. inspectRes.package.targetFile = inspectRes.plugin.targetFile;
  2910. }
  2911. const { plugin, meta, package: depTree, callGraph } = inspectRes;
  2912. if (depTree && !depTree.targetFile && plugin) {
  2913. depTree.targetFile = plugin.targetFile;
  2914. }
  2915. return {
  2916. plugin,
  2917. scannedProjects: [
  2918. {
  2919. plugin: plugin,
  2920. depTree,
  2921. callGraph: callGraph,
  2922. meta,
  2923. targetFile: plugin.targetFile,
  2924. packageManager,
  2925. },
  2926. ],
  2927. };
  2928. }
  2929. /***/ }),
  2930. /***/ 22805:
  2931. /***/ ((__unused_webpack_module, exports) => {
  2932. "use strict";
  2933. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2934. exports.extractPackageManager = void 0;
  2935. function extractPackageManager(scannedProject, pluginRes, options) {
  2936. // try and use the package Manager from the plugin
  2937. // result if present
  2938. const packageManager = scannedProject.packageManager ||
  2939. (pluginRes.plugin && pluginRes.plugin.packageManager);
  2940. if (packageManager) {
  2941. return packageManager;
  2942. }
  2943. if (!packageManager && options.packageManager) {
  2944. // fallback to Options packageManager
  2945. return options.packageManager;
  2946. }
  2947. // for example: docker
  2948. return undefined;
  2949. }
  2950. exports.extractPackageManager = extractPackageManager;
  2951. /***/ }),
  2952. /***/ 4842:
  2953. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  2954. "use strict";
  2955. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2956. exports.warnSomeGradleManifestsNotScanned = exports.getDepsFromPlugin = void 0;
  2957. const debugModule = __webpack_require__(15158);
  2958. const pathLib = __webpack_require__(85622);
  2959. const chalk_1 = __webpack_require__(32589);
  2960. const theme_1 = __webpack_require__(86988);
  2961. const cli_interface_1 = __webpack_require__(65266);
  2962. const find_files_1 = __webpack_require__(46123);
  2963. const errors_1 = __webpack_require__(55191);
  2964. const get_multi_plugin_result_1 = __webpack_require__(66058);
  2965. const get_single_plugin_result_1 = __webpack_require__(8598);
  2966. const detect_1 = __webpack_require__(45318);
  2967. const analytics = __webpack_require__(82744);
  2968. const convert_single_splugin_res_to_multi_custom_1 = __webpack_require__(99695);
  2969. const convert_multi_plugin_res_to_multi_custom_1 = __webpack_require__(23110);
  2970. const yarn_workspaces_parser_1 = __webpack_require__(27326);
  2971. const debug = debugModule('snyk-test');
  2972. const multiProjectProcessors = {
  2973. yarnWorkspaces: {
  2974. handler: yarn_workspaces_parser_1.processYarnWorkspaces,
  2975. files: ['package.json'],
  2976. },
  2977. allProjects: {
  2978. handler: get_multi_plugin_result_1.getMultiPluginResult,
  2979. files: detect_1.AUTO_DETECTABLE_FILES,
  2980. },
  2981. };
  2982. // Force getDepsFromPlugin to return scannedProjects for processing
  2983. async function getDepsFromPlugin(root, options) {
  2984. let inspectRes;
  2985. if (Object.keys(multiProjectProcessors).some((key) => options[key])) {
  2986. const scanType = options.yarnWorkspaces ? 'yarnWorkspaces' : 'allProjects';
  2987. const levelsDeep = options.detectionDepth;
  2988. const ignore = options.exclude ? options.exclude.split(',') : [];
  2989. const { files: targetFiles, allFilesFound } = await find_files_1.find(root, ignore, multiProjectProcessors[scanType].files, levelsDeep);
  2990. debug(`auto detect manifest files, found ${targetFiles.length}`, targetFiles);
  2991. if (targetFiles.length === 0) {
  2992. throw errors_1.NoSupportedManifestsFoundError([root]);
  2993. }
  2994. // enable full sub-project scan for gradle
  2995. options.allSubProjects = true;
  2996. inspectRes = await multiProjectProcessors[scanType].handler(root, options, targetFiles);
  2997. const scannedProjects = inspectRes.scannedProjects;
  2998. const analyticData = {
  2999. scannedProjects: scannedProjects.length,
  3000. targetFiles,
  3001. packageManagers: targetFiles.map((file) => detect_1.detectPackageManagerFromFile(file)),
  3002. levelsDeep,
  3003. ignore,
  3004. };
  3005. analytics.add(scanType, analyticData);
  3006. debug(`Found ${scannedProjects.length} projects from ${allFilesFound.length} detected manifests`);
  3007. const userWarningMessage = warnSomeGradleManifestsNotScanned(scannedProjects, allFilesFound, root);
  3008. if (!options.json && !options.quiet && userWarningMessage) {
  3009. console.warn(chalk_1.default.bold.red(userWarningMessage));
  3010. }
  3011. return inspectRes;
  3012. }
  3013. // TODO: is this needed for the auto detect handling above?
  3014. // don't override options.file if scanning multiple files at once
  3015. if (!options.scanAllUnmanaged) {
  3016. options.file = options.file || detect_1.detectPackageFile(root);
  3017. }
  3018. if (!options.docker && !(options.file || options.packageManager)) {
  3019. throw errors_1.NoSupportedManifestsFoundError([...root]);
  3020. }
  3021. inspectRes = await get_single_plugin_result_1.getSinglePluginResult(root, options);
  3022. if (!cli_interface_1.legacyPlugin.isMultiResult(inspectRes)) {
  3023. if (!inspectRes.package && !inspectRes.dependencyGraph) {
  3024. // something went wrong if both are not present...
  3025. throw Error(`error getting dependencies from ${options.docker ? 'docker' : options.packageManager} ` + "plugin: neither 'package' nor 'scannedProjects' were found");
  3026. }
  3027. return convert_single_splugin_res_to_multi_custom_1.convertSingleResultToMultiCustom(inspectRes, options.packageManager);
  3028. }
  3029. // We are using "options" to store some information returned from plugin that we need to use later,
  3030. // but don't want to send to Registry in the Payload.
  3031. // TODO(kyegupov): decouple inspect and payload so that we don't need this hack
  3032. options.projectNames = inspectRes.scannedProjects.map((scannedProject) => { var _a; return (_a = scannedProject === null || scannedProject === void 0 ? void 0 : scannedProject.depTree) === null || _a === void 0 ? void 0 : _a.name; });
  3033. return convert_multi_plugin_res_to_multi_custom_1.convertMultiResultToMultiCustom(inspectRes, options.packageManager);
  3034. }
  3035. exports.getDepsFromPlugin = getDepsFromPlugin;
  3036. function warnSomeGradleManifestsNotScanned(scannedProjects, allFilesFound, root) {
  3037. const gradleTargetFilesFilter = (targetFile) => targetFile &&
  3038. (targetFile.endsWith('build.gradle') ||
  3039. targetFile.endsWith('build.gradle.kts'));
  3040. const scannedGradleFiles = scannedProjects
  3041. .map((p) => {
  3042. var _a;
  3043. const targetFile = ((_a = p.meta) === null || _a === void 0 ? void 0 : _a.targetFile) || p.targetFile;
  3044. return targetFile ? pathLib.resolve(root, targetFile) : null;
  3045. })
  3046. .filter(gradleTargetFilesFilter);
  3047. const detectedGradleFiles = allFilesFound.filter(gradleTargetFilesFilter);
  3048. const diff = detectedGradleFiles.filter((file) => !scannedGradleFiles.includes(file));
  3049. if (diff.length > 0) {
  3050. debug(`These Gradle manifests did not return any dependency results:\n${diff.join(',\n')}`);
  3051. return `${theme_1.icon.ISSUE} ${diff.length}/${detectedGradleFiles.length} detected Gradle manifests did not return dependencies. They may have errored or were not included as part of a multi-project build. You may need to scan them individually with --file=path/to/file. Run with \`-d\` for more info.`;
  3052. }
  3053. return null;
  3054. }
  3055. exports.warnSomeGradleManifestsNotScanned = warnSomeGradleManifestsNotScanned;
  3056. /***/ }),
  3057. /***/ 34355:
  3058. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3059. "use strict";
  3060. Object.defineProperty(exports, "__esModule", ({ value: true }));
  3061. exports.getExtraProjectCount = void 0;
  3062. const find_files_1 = __webpack_require__(46123);
  3063. const detect_1 = __webpack_require__(45318);
  3064. async function getExtraProjectCount(root, options, inspectResult) {
  3065. if (options.docker || options.unmanaged) {
  3066. return undefined;
  3067. }
  3068. if (inspectResult.plugin.meta &&
  3069. inspectResult.plugin.meta.allSubProjectNames &&
  3070. inspectResult.plugin.meta.allSubProjectNames.length > 0) {
  3071. return inspectResult.plugin.meta.allSubProjectNames.length;
  3072. }
  3073. try {
  3074. const { files: extraTargetFiles } = await find_files_1.find(root, [], detect_1.AUTO_DETECTABLE_FILES);
  3075. const foundProjectsCount = extraTargetFiles.length > 1 ? extraTargetFiles.length - 1 : undefined;
  3076. return foundProjectsCount;
  3077. }
  3078. catch (e) {
  3079. return undefined;
  3080. }
  3081. }
  3082. exports.getExtraProjectCount = getExtraProjectCount;
  3083. /***/ }),
  3084. /***/ 66058:
  3085. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3086. "use strict";
  3087. Object.defineProperty(exports, "__esModule", ({ value: true }));
  3088. exports.filterOutProcessedWorkspaces = exports.getMultiPluginResult = void 0;
  3089. const cloneDeep = __webpack_require__(83465);
  3090. const pathLib = __webpack_require__(85622);
  3091. const cliInterface = __webpack_require__(65266);
  3092. const chalk_1 = __webpack_require__(32589);
  3093. const theme_1 = __webpack_require__(86988);
  3094. const debugModule = __webpack_require__(15158);
  3095. const detect_1 = __webpack_require__(45318);
  3096. const get_single_plugin_result_1 = __webpack_require__(8598);
  3097. const convert_single_splugin_res_to_multi_custom_1 = __webpack_require__(99695);
  3098. const convert_multi_plugin_res_to_multi_custom_1 = __webpack_require__(23110);
  3099. const errors_1 = __webpack_require__(55191);
  3100. const yarn_workspaces_parser_1 = __webpack_require__(27326);
  3101. const debug = debugModule('snyk-test');
  3102. async function getMultiPluginResult(root, options, targetFiles) {
  3103. var _a;
  3104. const allResults = [];
  3105. const failedResults = [];
  3106. // process any yarn workspaces first
  3107. // the files need to be proceeded together as they provide context to each other
  3108. const { scannedProjects, unprocessedFiles, } = await processYarnWorkspacesProjects(root, options, targetFiles);
  3109. allResults.push(...scannedProjects);
  3110. debug(`Not part of a workspace: ${unprocessedFiles.join(', ')}}`);
  3111. // process the rest 1 by 1 sent to relevant plugins
  3112. for (const targetFile of unprocessedFiles) {
  3113. const optionsClone = cloneDeep(options);
  3114. optionsClone.file = pathLib.relative(root, targetFile);
  3115. optionsClone.packageManager = detect_1.detectPackageManagerFromFile(pathLib.basename(targetFile));
  3116. try {
  3117. const inspectRes = await get_single_plugin_result_1.getSinglePluginResult(root, optionsClone, optionsClone.file);
  3118. let resultWithScannedProjects;
  3119. if (!cliInterface.legacyPlugin.isMultiResult(inspectRes)) {
  3120. resultWithScannedProjects = convert_single_splugin_res_to_multi_custom_1.convertSingleResultToMultiCustom(inspectRes, optionsClone.packageManager);
  3121. }
  3122. else {
  3123. resultWithScannedProjects = inspectRes;
  3124. }
  3125. const pluginResultWithCustomScannedProjects = convert_multi_plugin_res_to_multi_custom_1.convertMultiResultToMultiCustom(resultWithScannedProjects, optionsClone.packageManager, optionsClone.file);
  3126. // annotate the package manager, project name & targetFile to be used
  3127. // for test & monitor
  3128. // TODO: refactor how we display meta to not have to do this
  3129. options.projectNames = resultWithScannedProjects.scannedProjects.map((scannedProject) => { var _a; return (_a = scannedProject === null || scannedProject === void 0 ? void 0 : scannedProject.depTree) === null || _a === void 0 ? void 0 : _a.name; });
  3130. allResults.push(...pluginResultWithCustomScannedProjects.scannedProjects);
  3131. }
  3132. catch (error) {
  3133. const errMessage = (_a = error.message) !== null && _a !== void 0 ? _a : 'Something went wrong getting dependencies';
  3134. // TODO: propagate this all the way back and include in --json output
  3135. failedResults.push({
  3136. targetFile,
  3137. error,
  3138. errMessage: errMessage,
  3139. });
  3140. debug(chalk_1.default.bold.red(`\n${theme_1.icon.ISSUE} Failed to get dependencies for ${targetFile}\nERROR: ${errMessage}\n`));
  3141. }
  3142. }
  3143. if (!allResults.length) {
  3144. throw new errors_1.FailedToRunTestError(errors_1.errorMessageWithRetry(`Failed to get dependencies for all ${targetFiles.length} potential projects.`));
  3145. }
  3146. return {
  3147. plugin: {
  3148. name: 'custom-auto-detect',
  3149. },
  3150. scannedProjects: allResults,
  3151. failedResults,
  3152. };
  3153. }
  3154. exports.getMultiPluginResult = getMultiPluginResult;
  3155. async function processYarnWorkspacesProjects(root, options, targetFiles) {
  3156. try {
  3157. const { scannedProjects } = await yarn_workspaces_parser_1.processYarnWorkspaces(root, {
  3158. strictOutOfSync: options.strictOutOfSync,
  3159. dev: options.dev,
  3160. }, targetFiles);
  3161. const unprocessedFiles = filterOutProcessedWorkspaces(root, scannedProjects, targetFiles);
  3162. return { scannedProjects, unprocessedFiles };
  3163. }
  3164. catch (e) {
  3165. debug('Error during detecting or processing Yarn Workspaces: ', e);
  3166. return { scannedProjects: [], unprocessedFiles: targetFiles };
  3167. }
  3168. }
  3169. function filterOutProcessedWorkspaces(root, scannedProjects, allTargetFiles) {
  3170. const targetFiles = [];
  3171. const scanned = scannedProjects
  3172. .map((p) => p.targetFile)
  3173. .map((p) => pathLib.resolve(process.cwd(), root, p));
  3174. const all = allTargetFiles.map((p) => ({
  3175. path: pathLib.resolve(process.cwd(), root, p),
  3176. original: p,
  3177. }));
  3178. for (const entry of all) {
  3179. const { path, original } = entry;
  3180. const { base } = pathLib.parse(path);
  3181. if (!['package.json', 'yarn.lock'].includes(base)) {
  3182. targetFiles.push(original);
  3183. continue;
  3184. }
  3185. // standardise to package.json
  3186. // we discover the lockfiles but targetFile is package.json
  3187. if (!scanned.includes(path.replace('yarn.lock', 'package.json'))) {
  3188. targetFiles.push(original);
  3189. continue;
  3190. }
  3191. }
  3192. return targetFiles;
  3193. }
  3194. exports.filterOutProcessedWorkspaces = filterOutProcessedWorkspaces;
  3195. /***/ }),
  3196. /***/ 8598:
  3197. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3198. "use strict";
  3199. Object.defineProperty(exports, "__esModule", ({ value: true }));
  3200. exports.getSinglePluginResult = void 0;
  3201. const plugins = __webpack_require__(45632);
  3202. const module_info_1 = __webpack_require__(80777);
  3203. async function getSinglePluginResult(root, options, targetFile) {
  3204. const plugin = plugins.loadPlugin(options.packageManager);
  3205. const moduleInfo = module_info_1.ModuleInfo(plugin, options.policy);
  3206. const inspectRes = await moduleInfo.inspect(root, targetFile || options.file, { ...options });
  3207. return inspectRes;
  3208. }
  3209. exports.getSinglePluginResult = getSinglePluginResult;
  3210. /***/ }),
  3211. /***/ 45632:
  3212. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3213. "use strict";
  3214. Object.defineProperty(exports, "__esModule", ({ value: true }));
  3215. exports.loadPlugin = void 0;
  3216. const rubygemsPlugin = __webpack_require__(92632);
  3217. const mvnPlugin = __webpack_require__(29615);
  3218. const gradlePlugin = __webpack_require__(71673);
  3219. const sbtPlugin = __webpack_require__(1444);
  3220. const pythonPlugin = __webpack_require__(85054);
  3221. const goPlugin = __webpack_require__(29376);
  3222. const nugetPlugin = __webpack_require__(82843);
  3223. const phpPlugin = __webpack_require__(18630);
  3224. const nodejsPlugin = __webpack_require__(59947);
  3225. const cocoapodsPlugin = __webpack_require__(49556);
  3226. const hexPlugin = __webpack_require__(1649);
  3227. const errors_1 = __webpack_require__(55191);
  3228. function loadPlugin(packageManager) {
  3229. switch (packageManager) {
  3230. case 'npm': {
  3231. return nodejsPlugin;
  3232. }
  3233. case 'rubygems': {
  3234. return rubygemsPlugin;
  3235. }
  3236. case 'maven': {
  3237. return mvnPlugin;
  3238. }
  3239. case 'gradle': {
  3240. return gradlePlugin;
  3241. }
  3242. case 'sbt': {
  3243. return sbtPlugin;
  3244. }
  3245. case 'yarn': {
  3246. return nodejsPlugin;
  3247. }
  3248. case 'pip':
  3249. case 'poetry': {
  3250. return pythonPlugin;
  3251. }
  3252. case 'golangdep':
  3253. case 'gomodules':
  3254. case 'govendor': {
  3255. return goPlugin;
  3256. }
  3257. case 'nuget': {
  3258. return nugetPlugin;
  3259. }
  3260. case 'paket': {
  3261. return nugetPlugin;
  3262. }
  3263. case 'composer': {
  3264. return phpPlugin;
  3265. }
  3266. case 'cocoapods': {
  3267. return cocoapodsPlugin;
  3268. }
  3269. case 'hex': {
  3270. return hexPlugin;
  3271. }
  3272. default: {
  3273. throw new errors_1.UnsupportedPackageManagerError(packageManager);
  3274. }
  3275. }
  3276. }
  3277. exports.loadPlugin = loadPlugin;
  3278. /***/ }),
  3279. /***/ 59947:
  3280. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3281. "use strict";
  3282. Object.defineProperty(exports, "__esModule", ({ value: true }));
  3283. exports.inspect = void 0;
  3284. const modulesParser = __webpack_require__(85994);
  3285. const lockParser = __webpack_require__(82791);
  3286. const analytics = __webpack_require__(82744);
  3287. const missing_targetfile_error_1 = __webpack_require__(56775);
  3288. async function inspect(root, targetFile, options = {}) {
  3289. var _a;
  3290. if (!targetFile) {
  3291. throw missing_targetfile_error_1.MissingTargetFileError(root);
  3292. }
  3293. const isLockFileBased = targetFile.endsWith('package-lock.json') ||
  3294. targetFile.endsWith('yarn.lock');
  3295. const getLockFileDeps = isLockFileBased && !options.traverseNodeModules;
  3296. const depTree = getLockFileDeps
  3297. ? await lockParser.parse(root, targetFile, options)
  3298. : await modulesParser.parse(root, targetFile, options);
  3299. if ((_a = depTree === null || depTree === void 0 ? void 0 : depTree.meta) === null || _a === void 0 ? void 0 : _a.lockfileVersion) {
  3300. analytics.add('lockfileVersion', depTree.meta.lockfileVersion);
  3301. }
  3302. return {
  3303. plugin: {
  3304. name: 'snyk-nodejs-lockfile-parser',
  3305. runtime: process.version,
  3306. },
  3307. scannedProjects: [{ depTree }],
  3308. };
  3309. }
  3310. exports.inspect = inspect;
  3311. /***/ }),
  3312. /***/ 82791:
  3313. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3314. "use strict";
  3315. Object.defineProperty(exports, "__esModule", ({ value: true }));
  3316. exports.parse = void 0;
  3317. const baseDebug = __webpack_require__(15158);
  3318. const debug = baseDebug('snyk-test');
  3319. const path = __webpack_require__(85622);
  3320. const spinner_1 = __webpack_require__(86766);
  3321. const analytics = __webpack_require__(82744);
  3322. const fs = __webpack_require__(35747);
  3323. const lockFileParser = __webpack_require__(423);
  3324. async function parse(root, targetFile, options) {
  3325. const lockFileFullPath = path.resolve(root, targetFile);
  3326. if (!fs.existsSync(lockFileFullPath)) {
  3327. throw new Error('Lockfile ' + targetFile + ' not found at location: ' + lockFileFullPath);
  3328. }
  3329. const fullPath = path.parse(lockFileFullPath);
  3330. const manifestFileFullPath = path.resolve(fullPath.dir, 'package.json');
  3331. const shrinkwrapFullPath = path.resolve(fullPath.dir, 'npm-shrinkwrap.json');
  3332. if (!fs.existsSync(manifestFileFullPath)) {
  3333. throw new Error(`Could not find package.json at ${manifestFileFullPath} ` +
  3334. `(lockfile found at ${targetFile})`);
  3335. }
  3336. if (fs.existsSync(shrinkwrapFullPath)) {
  3337. throw new Error('Both `npm-shrinkwrap.json` and `package-lock.json` were found in ' +
  3338. fullPath.dir +
  3339. '.\n' +
  3340. 'Please run your command again specifying `--file=package.json` flag.');
  3341. }
  3342. analytics.add('local', true);
  3343. analytics.add('generating-node-dependency-tree', {
  3344. lockFile: true,
  3345. targetFile,
  3346. });
  3347. const resolveModuleSpinnerLabel = `Analyzing npm dependencies for ${lockFileFullPath}`;
  3348. debug(resolveModuleSpinnerLabel);
  3349. try {
  3350. await spinner_1.spinner(resolveModuleSpinnerLabel);
  3351. const strictOutOfSync = options.strictOutOfSync !== false;
  3352. return lockFileParser.buildDepTreeFromFiles(root, manifestFileFullPath, lockFileFullPath, options.dev, strictOutOfSync);
  3353. }
  3354. finally {
  3355. await spinner_1.spinner.clear(resolveModuleSpinnerLabel)();
  3356. }
  3357. }
  3358. exports.parse = parse;
  3359. /***/ }),
  3360. /***/ 85994:
  3361. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3362. "use strict";
  3363. Object.defineProperty(exports, "__esModule", ({ value: true }));
  3364. exports.parse = void 0;
  3365. const path = __webpack_require__(85622);
  3366. const fs = __webpack_require__(35747);
  3367. const resolveNodeDeps = __webpack_require__(40068);
  3368. const baseDebug = __webpack_require__(15158);
  3369. const isEmpty = __webpack_require__(99245);
  3370. const spinner_1 = __webpack_require__(86766);
  3371. const analytics = __webpack_require__(82744);
  3372. const get_file_contents_1 = __webpack_require__(84210);
  3373. const debug = baseDebug('snyk-nodejs-plugin');
  3374. async function parse(root, targetFile, options) {
  3375. if (targetFile.endsWith('yarn.lock')) {
  3376. options.file =
  3377. options.file && options.file.replace('yarn.lock', 'package.json');
  3378. }
  3379. // package-lock.json falls back to package.json (used in wizard code)
  3380. if (targetFile.endsWith('package-lock.json')) {
  3381. options.file =
  3382. options.file && options.file.replace('package-lock.json', 'package.json');
  3383. }
  3384. // check if there any dependencies
  3385. const packageJsonFileName = path.resolve(root, options.file);
  3386. const packageManager = options.packageManager || 'npm';
  3387. try {
  3388. const packageJson = JSON.parse(get_file_contents_1.getFileContents(root, packageJsonFileName).content);
  3389. let dependencies = packageJson.dependencies;
  3390. if (options.dev) {
  3391. dependencies = { ...dependencies, ...packageJson.devDependencies };
  3392. }
  3393. if (isEmpty(dependencies)) {
  3394. return new Promise((resolve) => resolve({
  3395. name: packageJson.name || 'package.json',
  3396. dependencies: {},
  3397. version: packageJson.version,
  3398. }));
  3399. }
  3400. }
  3401. catch (e) {
  3402. debug(`Failed to read ${packageJsonFileName}: Error: ${e}`);
  3403. throw new Error(`Failed to read ${packageJsonFileName}. Error: ${e.message}`);
  3404. }
  3405. const nodeModulesPath = path.join(path.dirname(path.resolve(root, targetFile)), 'node_modules');
  3406. if (!fs.existsSync(nodeModulesPath)) {
  3407. // throw a custom error
  3408. throw new Error("Missing node_modules folder: we can't test " +
  3409. `without dependencies.\nPlease run '${packageManager} install' first.`);
  3410. }
  3411. analytics.add('local', true);
  3412. analytics.add('generating-node-dependency-tree', {
  3413. lockFile: false,
  3414. targetFile,
  3415. });
  3416. const resolveModuleSpinnerLabel = 'Analyzing npm dependencies for ' +
  3417. path.dirname(path.resolve(root, targetFile));
  3418. try {
  3419. await spinner_1.spinner.clear(resolveModuleSpinnerLabel)();
  3420. await spinner_1.spinner(resolveModuleSpinnerLabel);
  3421. return resolveNodeDeps(root, Object.assign({}, options, { noFromArrays: true }));
  3422. }
  3423. finally {
  3424. await spinner_1.spinner.clear(resolveModuleSpinnerLabel)();
  3425. }
  3426. }
  3427. exports.parse = parse;
  3428. /***/ }),
  3429. /***/ 27326:
  3430. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3431. "use strict";
  3432. Object.defineProperty(exports, "__esModule", ({ value: true }));
  3433. exports.packageJsonBelongsToWorkspace = exports.getWorkspacesMap = exports.processYarnWorkspaces = void 0;
  3434. const baseDebug = __webpack_require__(15158);
  3435. const pathUtil = __webpack_require__(85622);
  3436. const sortBy = __webpack_require__(58254);
  3437. const groupBy = __webpack_require__(20276);
  3438. const micromatch = __webpack_require__(70850);
  3439. const debug = baseDebug('snyk-yarn-workspaces');
  3440. const lockFileParser = __webpack_require__(423);
  3441. const get_file_contents_1 = __webpack_require__(84210);
  3442. const errors_1 = __webpack_require__(55191);
  3443. async function processYarnWorkspaces(root, settings, targetFiles) {
  3444. // the order of yarnTargetFiles folders is important
  3445. // must have the root level most folders at the top
  3446. const mappedAndFiltered = targetFiles
  3447. .map((p) => ({ path: p, ...pathUtil.parse(p) }))
  3448. .filter((res) => ['package.json', 'yarn.lock'].includes(res.base));
  3449. const sorted = sortBy(mappedAndFiltered, 'dir');
  3450. const grouped = groupBy(sorted, 'dir');
  3451. const yarnTargetFiles = grouped;
  3452. debug(`Processing potential Yarn workspaces (${targetFiles.length})`);
  3453. if (settings.yarnWorkspaces && Object.keys(yarnTargetFiles).length === 0) {
  3454. throw errors_1.NoSupportedManifestsFoundError([root]);
  3455. }
  3456. let yarnWorkspacesMap = {};
  3457. const yarnWorkspacesFilesMap = {};
  3458. const result = {
  3459. plugin: {
  3460. name: 'snyk-nodejs-yarn-workspaces',
  3461. runtime: process.version,
  3462. },
  3463. scannedProjects: [],
  3464. };
  3465. let rootWorkspaceManifestContent = {};
  3466. // the folders must be ordered highest first
  3467. for (const directory of Object.keys(yarnTargetFiles)) {
  3468. debug(`Processing ${directory} as a potential Yarn workspace`);
  3469. let isYarnWorkspacePackage = false;
  3470. let isRootPackageJson = false;
  3471. const packageJsonFileName = pathUtil.join(directory, 'package.json');
  3472. const packageJson = get_file_contents_1.getFileContents(root, packageJsonFileName);
  3473. yarnWorkspacesMap = {
  3474. ...yarnWorkspacesMap,
  3475. ...getWorkspacesMap(packageJson),
  3476. };
  3477. for (const workspaceRoot of Object.keys(yarnWorkspacesMap)) {
  3478. const match = packageJsonBelongsToWorkspace(packageJsonFileName, yarnWorkspacesMap, workspaceRoot);
  3479. if (match) {
  3480. debug(`${packageJsonFileName} matches an existing workspace pattern`);
  3481. yarnWorkspacesFilesMap[packageJsonFileName] = {
  3482. root: workspaceRoot,
  3483. };
  3484. isYarnWorkspacePackage = true;
  3485. }
  3486. if (packageJsonFileName === workspaceRoot) {
  3487. isRootPackageJson = true;
  3488. rootWorkspaceManifestContent = JSON.parse(packageJson.content);
  3489. }
  3490. }
  3491. if (!(isYarnWorkspacePackage || isRootPackageJson)) {
  3492. debug(`${packageJsonFileName} is not part of any detected workspace, skipping`);
  3493. continue;
  3494. }
  3495. try {
  3496. const rootDir = isYarnWorkspacePackage
  3497. ? pathUtil.dirname(yarnWorkspacesFilesMap[packageJsonFileName].root)
  3498. : pathUtil.dirname(packageJsonFileName);
  3499. const rootYarnLockfileName = pathUtil.join(rootDir, 'yarn.lock');
  3500. const yarnLock = await get_file_contents_1.getFileContents(root, rootYarnLockfileName);
  3501. if (rootWorkspaceManifestContent.hasOwnProperty('resolutions') &&
  3502. lockFileParser.getYarnLockfileType(yarnLock.content) ===
  3503. lockFileParser.LockfileType.yarn2) {
  3504. const parsedManifestContent = JSON.parse(packageJson.content);
  3505. packageJson.content = JSON.stringify({
  3506. ...parsedManifestContent,
  3507. resolutions: rootWorkspaceManifestContent['resolutions'],
  3508. });
  3509. }
  3510. const res = await lockFileParser.buildDepTree(packageJson.content, yarnLock.content, settings.dev, lockFileParser.LockfileType.yarn, settings.strictOutOfSync !== false);
  3511. const project = {
  3512. packageManager: 'yarn',
  3513. targetFile: pathUtil.relative(root, packageJson.fileName),
  3514. depTree: res,
  3515. plugin: {
  3516. name: 'snyk-nodejs-lockfile-parser',
  3517. runtime: process.version,
  3518. },
  3519. };
  3520. result.scannedProjects.push(project);
  3521. }
  3522. catch (e) {
  3523. if (settings.yarnWorkspaces) {
  3524. throw e;
  3525. }
  3526. debug(`Error process workspace: ${packageJsonFileName}. ERROR: ${e}`);
  3527. }
  3528. }
  3529. if (!result.scannedProjects.length) {
  3530. debug(`No yarn workspaces detected in any of the ${targetFiles.length} target files.`);
  3531. }
  3532. return result;
  3533. }
  3534. exports.processYarnWorkspaces = processYarnWorkspaces;
  3535. function getWorkspacesMap(file) {
  3536. const yarnWorkspacesMap = {};
  3537. if (!file) {
  3538. return yarnWorkspacesMap;
  3539. }
  3540. try {
  3541. const rootFileWorkspacesDefinitions = lockFileParser.getYarnWorkspaces(file.content);
  3542. if (rootFileWorkspacesDefinitions && rootFileWorkspacesDefinitions.length) {
  3543. yarnWorkspacesMap[file.fileName] = {
  3544. workspaces: rootFileWorkspacesDefinitions,
  3545. };
  3546. }
  3547. }
  3548. catch (e) {
  3549. debug('Failed to process a workspace', e.message);
  3550. }
  3551. return yarnWorkspacesMap;
  3552. }
  3553. exports.getWorkspacesMap = getWorkspacesMap;
  3554. function packageJsonBelongsToWorkspace(packageJsonFileName, yarnWorkspacesMap, workspaceRoot) {
  3555. const workspaceRootFolder = pathUtil.dirname(workspaceRoot.replace(/\\/g, '/'));
  3556. const workspacesGlobs = (yarnWorkspacesMap[workspaceRoot].workspaces || []).map((workspace) => pathUtil.join(workspaceRootFolder, workspace));
  3557. const match = micromatch.isMatch(packageJsonFileName.replace(/\\/g, '/'), workspacesGlobs.map((p) => pathUtil.normalize(pathUtil.join(p, '**')).replace(/\\/g, '/')));
  3558. return match;
  3559. }
  3560. exports.packageJsonBelongsToWorkspace = packageJsonBelongsToWorkspace;
  3561. /***/ }),
  3562. /***/ 92632:
  3563. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3564. "use strict";
  3565. Object.defineProperty(exports, "__esModule", ({ value: true }));
  3566. exports.inspect = void 0;
  3567. const inspectors_1 = __webpack_require__(9438);
  3568. const missing_targetfile_error_1 = __webpack_require__(56775);
  3569. const gemfileLockToDependencies = __webpack_require__(97467);
  3570. const get = __webpack_require__(29208);
  3571. async function inspect(root, targetFile, options = {}) {
  3572. if (!targetFile) {
  3573. throw missing_targetfile_error_1.MissingTargetFileError(root);
  3574. }
  3575. const specs = await gatherSpecs(root, targetFile, options);
  3576. return {
  3577. plugin: {
  3578. name: 'bundled:rubygems',
  3579. runtime: 'unknown',
  3580. },
  3581. scannedProjects: [
  3582. {
  3583. depTree: {
  3584. name: specs.packageName,
  3585. targetFile: specs.targetFile,
  3586. dependencies: getDependenciesFromSpecs(specs),
  3587. },
  3588. },
  3589. ],
  3590. };
  3591. }
  3592. exports.inspect = inspect;
  3593. function getDependenciesFromSpecs(specs) {
  3594. const gemfileLockBase64 = get(specs, 'files.gemfileLock.contents');
  3595. const gemspecBase64 = get(specs, 'files.gemspec.contents');
  3596. const contents = Buffer.from(gemfileLockBase64 || gemspecBase64, 'base64').toString();
  3597. const dependencies = gemfileLockToDependencies(contents);
  3598. return dependencies;
  3599. }
  3600. async function gatherSpecs(root, targetFile, options) {
  3601. for (const inspector of inspectors_1.inspectors) {
  3602. if (inspector.canHandle(targetFile)) {
  3603. return await inspector.gatherSpecs(root, targetFile, options);
  3604. }
  3605. }
  3606. throw new Error(`Could not handle rubygems file: ${targetFile}`);
  3607. }
  3608. /***/ }),
  3609. /***/ 9162:
  3610. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3611. "use strict";
  3612. Object.defineProperty(exports, "__esModule", ({ value: true }));
  3613. exports.gatherSpecs = exports.canHandle = void 0;
  3614. const path = __webpack_require__(85622);
  3615. const try_get_spec_1 = __webpack_require__(50552);
  3616. /* Supported example patterns:
  3617. * Gemfile
  3618. * Gemfile.lock
  3619. * rails.2.4.5.gemfile
  3620. * rails.2.4.5.gemfile.lock
  3621. * gemfiles/Gemfile.rails-2.4.5.lock
  3622. * gemfiles/Gemfile.lock.rails-2.4.5
  3623. */
  3624. const gemfileOrLockfilePattern = /.*[gG]emfile.*(\.lock)?.*$/;
  3625. const gemfileLockPattern = /.*[gG]emfile.*(\.lock).*$/;
  3626. function canHandle(file) {
  3627. return !!file && gemfileOrLockfilePattern.test(path.basename(file));
  3628. }
  3629. exports.canHandle = canHandle;
  3630. async function gatherSpecs(root, target, options) {
  3631. const { dir, name } = path.parse(target);
  3632. const isGemfileLock = gemfileLockPattern.test(target);
  3633. // if the target is a Gemfile we treat is as the lockfile
  3634. const gemfileLock = await try_get_spec_1.tryGetSpec(root, isGemfileLock ? target : path.join(target + '.lock'));
  3635. if (gemfileLock) {
  3636. const basePackageName = path.basename(root);
  3637. return {
  3638. packageName: options.allSubProjects
  3639. ? path.join(basePackageName, dir)
  3640. : basePackageName,
  3641. targetFile: path.join(dir, name),
  3642. files: { gemfileLock },
  3643. };
  3644. }
  3645. else {
  3646. throw new Error(`Could not read ${target || 'Gemfile.lock'} lockfile: can't test ` +
  3647. 'without dependencies.\nPlease run `bundle install` first or' +
  3648. ' if this is a custom file name re-run with --file=path/to/custom.gemfile.lock --package-manager=rubygems');
  3649. }
  3650. }
  3651. exports.gatherSpecs = gatherSpecs;
  3652. /***/ }),
  3653. /***/ 31810:
  3654. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3655. "use strict";
  3656. Object.defineProperty(exports, "__esModule", ({ value: true }));
  3657. exports.gatherSpecs = exports.canHandle = void 0;
  3658. const path = __webpack_require__(85622);
  3659. const try_get_spec_1 = __webpack_require__(50552);
  3660. const pattern = /\.gemspec$/;
  3661. function canHandle(file) {
  3662. return !!file && pattern.test(file);
  3663. }
  3664. exports.canHandle = canHandle;
  3665. async function gatherSpecs(root, target) {
  3666. const targetName = path.basename(target);
  3667. const targetDir = path.dirname(target);
  3668. const files = {};
  3669. const gemspec = await try_get_spec_1.tryGetSpec(root, path.join(targetDir, targetName));
  3670. if (gemspec) {
  3671. files.gemspec = gemspec;
  3672. }
  3673. else {
  3674. throw new Error(`File not found: ${target}`);
  3675. }
  3676. const gemfileLock = await try_get_spec_1.tryGetSpec(root, path.join(targetDir, 'Gemfile.lock'));
  3677. if (gemfileLock) {
  3678. files.gemfileLock = gemfileLock;
  3679. }
  3680. return {
  3681. packageName: path.basename(root),
  3682. targetFile: path.join(targetDir, targetName),
  3683. files,
  3684. };
  3685. }
  3686. exports.gatherSpecs = gatherSpecs;
  3687. /***/ }),
  3688. /***/ 9438:
  3689. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3690. "use strict";
  3691. Object.defineProperty(exports, "__esModule", ({ value: true }));
  3692. exports.inspectors = void 0;
  3693. const gemfile = __webpack_require__(9162);
  3694. const gemspec = __webpack_require__(31810);
  3695. exports.inspectors = [gemfile, gemspec];
  3696. /***/ }),
  3697. /***/ 50552:
  3698. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3699. "use strict";
  3700. Object.defineProperty(exports, "__esModule", ({ value: true }));
  3701. exports.tryGetSpec = void 0;
  3702. const path = __webpack_require__(85622);
  3703. const fs = __webpack_require__(35747);
  3704. async function tryGetSpec(dir, name) {
  3705. const filePath = path.resolve(dir, name);
  3706. if (fs.existsSync(filePath)) {
  3707. return {
  3708. name,
  3709. contents: Buffer.from(fs.readFileSync(filePath)).toString('base64'),
  3710. };
  3711. }
  3712. return null;
  3713. }
  3714. exports.tryGetSpec = tryGetSpec;
  3715. /***/ }),
  3716. /***/ 2806:
  3717. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3718. "use strict";
  3719. Object.defineProperty(exports, "__esModule", ({ value: true }));
  3720. exports.getCodeAnalysisAndParseResults = void 0;
  3721. const code_client_1 = __webpack_require__(95951);
  3722. const legacy_1 = __webpack_require__(34013);
  3723. const api_token_1 = __webpack_require__(95181);
  3724. const config_1 = __webpack_require__(25425);
  3725. const code_config_1 = __webpack_require__(55203);
  3726. const spinner_1 = __webpack_require__(86766);
  3727. const utils_1 = __webpack_require__(33113);
  3728. const errors_1 = __webpack_require__(61315);
  3729. const proxy_from_env_1 = __webpack_require__(21394);
  3730. const global_agent_1 = __webpack_require__(97959);
  3731. const chalk_1 = __webpack_require__(32589);
  3732. const debugLib = __webpack_require__(15158);
  3733. const code_config_2 = __webpack_require__(55203);
  3734. const debug = debugLib('snyk-code');
  3735. async function getCodeAnalysisAndParseResults(root, options, sastSettings, requestId) {
  3736. await spinner_1.spinner.clearAll();
  3737. utils_1.analysisProgressUpdate();
  3738. const codeAnalysis = await getCodeAnalysis(root, options, sastSettings, requestId);
  3739. spinner_1.spinner.clearAll();
  3740. return parseSecurityResults(codeAnalysis);
  3741. }
  3742. exports.getCodeAnalysisAndParseResults = getCodeAnalysisAndParseResults;
  3743. async function getCodeAnalysis(root, options, sastSettings, requestId) {
  3744. var _a;
  3745. const isLocalCodeEngineEnabled = isLocalCodeEngine(sastSettings);
  3746. if (isLocalCodeEngineEnabled) {
  3747. validateLocalCodeEngineUrl(sastSettings.localCodeEngine.url);
  3748. }
  3749. const source = 'snyk-cli';
  3750. const baseURL = isLocalCodeEngineEnabled
  3751. ? sastSettings.localCodeEngine.url
  3752. : code_config_2.getCodeClientProxyUrl();
  3753. const base64Encoding = code_config_1.getBase64Encoding();
  3754. debug(`base64 encoding enabled: ${base64Encoding}`);
  3755. // TODO(james) This mirrors the implementation in request.ts and we need to use this for deeproxy calls
  3756. // This ensures we support lowercase http(s)_proxy values as well
  3757. // The weird IF around it ensures we don't create an envvar with
  3758. // a value of undefined, which throws error when trying to use it as a proxy
  3759. if (process.env.HTTP_PROXY || process.env.http_proxy) {
  3760. process.env.HTTP_PROXY = process.env.HTTP_PROXY || process.env.http_proxy;
  3761. }
  3762. if (process.env.HTTPS_PROXY || process.env.https_proxy) {
  3763. process.env.HTTPS_PROXY =
  3764. process.env.HTTPS_PROXY || process.env.https_proxy;
  3765. }
  3766. const proxyUrl = proxy_from_env_1.getProxyForUrl(baseURL);
  3767. if (proxyUrl) {
  3768. global_agent_1.bootstrap({
  3769. environmentVariableNamespace: '',
  3770. });
  3771. }
  3772. const sessionToken = api_token_1.api() || '';
  3773. const severity = options.severityThreshold
  3774. ? severityToAnalysisSeverity(options.severityThreshold)
  3775. : code_client_1.AnalysisSeverity.info;
  3776. const result = await code_client_1.analyzeFolders({
  3777. connection: { baseURL, sessionToken, source, requestId, base64Encoding },
  3778. analysisOptions: { severity },
  3779. fileOptions: { paths: [root] },
  3780. analysisContext: {
  3781. initiator: 'CLI',
  3782. flow: source,
  3783. orgDisplayName: sastSettings.org,
  3784. projectName: config_1.default.PROJECT_NAME,
  3785. org: {
  3786. name: sastSettings.org || 'unknown',
  3787. displayName: 'unknown',
  3788. publicId: 'unknown',
  3789. flags: {},
  3790. },
  3791. },
  3792. languages: sastSettings.supportedLanguages,
  3793. });
  3794. if ((_a = result === null || result === void 0 ? void 0 : result.fileBundle.skippedOversizedFiles) === null || _a === void 0 ? void 0 : _a.length) {
  3795. debug('\n', chalk_1.default.yellow(`Warning!\nFiles were skipped in the analysis due to their size being greater than ${code_client_1.MAX_FILE_SIZE}B. Skipped files: ${[
  3796. ...result.fileBundle.skippedOversizedFiles,
  3797. ].join(', ')}`));
  3798. }
  3799. if ((result === null || result === void 0 ? void 0 : result.analysisResults.type) === 'sarif') {
  3800. return result.analysisResults.sarif;
  3801. }
  3802. return null;
  3803. }
  3804. function severityToAnalysisSeverity(severity) {
  3805. if (severity === legacy_1.SEVERITY.CRITICAL) {
  3806. throw new errors_1.FeatureNotSupportedBySnykCodeError(legacy_1.SEVERITY.CRITICAL);
  3807. }
  3808. const severityLevel = {
  3809. low: 1,
  3810. medium: 2,
  3811. high: 3,
  3812. };
  3813. return severityLevel[severity];
  3814. }
  3815. function parseSecurityResults(codeAnalysis) {
  3816. let securityRulesMap;
  3817. if (!codeAnalysis) {
  3818. return codeAnalysis;
  3819. }
  3820. const rules = codeAnalysis.runs[0].tool.driver.rules;
  3821. const results = codeAnalysis.runs[0].results;
  3822. if (rules) {
  3823. securityRulesMap = getSecurityRulesMap(rules);
  3824. codeAnalysis.runs[0].tool.driver.rules = Object.values(securityRulesMap);
  3825. }
  3826. if (results && securityRulesMap) {
  3827. codeAnalysis.runs[0].results = getSecurityResultsOnly(results, Object.keys(securityRulesMap));
  3828. }
  3829. return codeAnalysis;
  3830. }
  3831. function getSecurityRulesMap(rules) {
  3832. const securityRulesMap = rules.reduce((acc, rule) => {
  3833. var _a;
  3834. const { id: ruleId, properties } = rule;
  3835. const isSecurityRule = (_a = properties === null || properties === void 0 ? void 0 : properties.categories) === null || _a === void 0 ? void 0 : _a.some((category) => category.toLowerCase() === 'security');
  3836. if (isSecurityRule) {
  3837. acc[ruleId] = rule;
  3838. }
  3839. return acc;
  3840. }, {});
  3841. return securityRulesMap;
  3842. }
  3843. function getSecurityResultsOnly(results, securityRules) {
  3844. const securityResults = results.reduce((acc, result) => {
  3845. const securityRule = securityRules.find((sr) => sr === (result === null || result === void 0 ? void 0 : result.ruleId));
  3846. if (securityRule) {
  3847. result.ruleIndex = securityRules.indexOf(securityRule);
  3848. acc.push(result);
  3849. }
  3850. return acc;
  3851. }, []);
  3852. return securityResults;
  3853. }
  3854. function isLocalCodeEngine(sastSettings) {
  3855. const { sastEnabled, localCodeEngine } = sastSettings;
  3856. return sastEnabled && localCodeEngine.enabled;
  3857. }
  3858. function validateLocalCodeEngineUrl(localCodeEngineUrl) {
  3859. if (localCodeEngineUrl.length === 0) {
  3860. throw new errors_1.MissingConfigurationError('Snyk Code Local Engine. Refer to our docs on https://docs.snyk.io/products/snyk-code/deployment-options/snyk-code-local-engine/cli-and-ide to learn more');
  3861. }
  3862. }
  3863. /***/ }),
  3864. /***/ 15976:
  3865. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3866. "use strict";
  3867. Object.defineProperty(exports, "__esModule", ({ value: true }));
  3868. exports.trackUsage = exports.getSastSettingsForOrg = void 0;
  3869. const request_1 = __webpack_require__(52050);
  3870. const api_token_1 = __webpack_require__(95181);
  3871. const config_1 = __webpack_require__(25425);
  3872. const common_1 = __webpack_require__(53110);
  3873. async function getSastSettingsForOrg(org) {
  3874. const response = await request_1.makeRequest({
  3875. method: 'GET',
  3876. headers: {
  3877. Authorization: api_token_1.getAuthHeader(),
  3878. },
  3879. qs: common_1.assembleQueryString({ org }),
  3880. url: `${config_1.default.API}/cli-config/settings/sast`,
  3881. gzip: true,
  3882. json: true,
  3883. });
  3884. return response.body;
  3885. }
  3886. exports.getSastSettingsForOrg = getSastSettingsForOrg;
  3887. async function trackUsage(org) {
  3888. const response = await request_1.makeRequest({
  3889. method: 'POST',
  3890. headers: {
  3891. Authorization: api_token_1.getAuthHeader(),
  3892. },
  3893. qs: common_1.assembleQueryString({ org }),
  3894. url: `${config_1.default.API}/track-sast-usage/cli`,
  3895. gzip: true,
  3896. json: true,
  3897. });
  3898. return response.body;
  3899. }
  3900. exports.trackUsage = trackUsage;
  3901. /***/ }),
  3902. /***/ 61315:
  3903. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3904. "use strict";
  3905. Object.defineProperty(exports, "__esModule", ({ value: true }));
  3906. var missing_configuration_error_1 = __webpack_require__(73016);
  3907. Object.defineProperty(exports, "MissingConfigurationError", ({ enumerable: true, get: function () { return missing_configuration_error_1.MissingConfigurationError; } }));
  3908. var unsupported_feature_snyk_code_error_1 = __webpack_require__(90551);
  3909. Object.defineProperty(exports, "FeatureNotSupportedBySnykCodeError", ({ enumerable: true, get: function () { return unsupported_feature_snyk_code_error_1.FeatureNotSupportedBySnykCodeError; } }));
  3910. /***/ }),
  3911. /***/ 73016:
  3912. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3913. "use strict";
  3914. Object.defineProperty(exports, "__esModule", ({ value: true }));
  3915. exports.MissingConfigurationError = void 0;
  3916. const custom_error_1 = __webpack_require__(17188);
  3917. class MissingConfigurationError extends custom_error_1.CustomError {
  3918. constructor(action, additionalUserHelp = '') {
  3919. super(`Missing configuration for ${action}.`);
  3920. this.code = 422;
  3921. this.action = action;
  3922. this.userMessage = `'Configuration is missing or wrong for ${action}'. ${additionalUserHelp}`;
  3923. }
  3924. }
  3925. exports.MissingConfigurationError = MissingConfigurationError;
  3926. /***/ }),
  3927. /***/ 90551:
  3928. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3929. "use strict";
  3930. Object.defineProperty(exports, "__esModule", ({ value: true }));
  3931. exports.FeatureNotSupportedBySnykCodeError = void 0;
  3932. const custom_error_1 = __webpack_require__(17188);
  3933. class FeatureNotSupportedBySnykCodeError extends custom_error_1.CustomError {
  3934. constructor(feature, additionalUserHelp = '') {
  3935. super(`Unsupported action for ${feature}.`);
  3936. this.code = 422;
  3937. this.feature = feature;
  3938. this.userMessage = `'${feature}' is not supported for snyk code. ${additionalUserHelp}`;
  3939. }
  3940. }
  3941. exports.FeatureNotSupportedBySnykCodeError = FeatureNotSupportedBySnykCodeError;
  3942. /***/ }),
  3943. /***/ 75802:
  3944. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3945. "use strict";
  3946. Object.defineProperty(exports, "__esModule", ({ value: true }));
  3947. exports.getPrefix = exports.getMeta = exports.getCodeDisplayedOutput = void 0;
  3948. const Debug = __webpack_require__(15158);
  3949. const chalk_1 = __webpack_require__(32589);
  3950. const theme_1 = __webpack_require__(86988);
  3951. const common_1 = __webpack_require__(53110);
  3952. const right_pad_1 = __webpack_require__(80627);
  3953. const debug = Debug('code-output');
  3954. function getCodeDisplayedOutput(codeTest, meta, prefix) {
  3955. let issues = {};
  3956. if (codeTest.runs[0].results) {
  3957. const results = codeTest.runs[0].results;
  3958. const rulesMap = getRulesMap(codeTest.runs[0].tool.driver.rules || []);
  3959. issues = getIssues(results, rulesMap);
  3960. }
  3961. const issuesText = issues.low.join('') + issues.medium.join('') + issues.high.join('');
  3962. const summaryOKText = theme_1.color.status.success(`${theme_1.icon.VALID} Test completed`);
  3963. const codeIssueSummary = getCodeIssuesSummary(issues);
  3964. return (prefix +
  3965. issuesText +
  3966. '\n' +
  3967. summaryOKText +
  3968. '\n\n' +
  3969. meta +
  3970. '\n\n' +
  3971. chalk_1.default.bold('Summary:') +
  3972. '\n\n' +
  3973. codeIssueSummary +
  3974. '\n\n');
  3975. }
  3976. exports.getCodeDisplayedOutput = getCodeDisplayedOutput;
  3977. function getCodeIssuesSummary(issues) {
  3978. const lowSeverityText = issues.low.length
  3979. ? common_1.colorTextBySeverity(common_1.SEVERITY.LOW, ` ${issues.low.length} [Low] `)
  3980. : '';
  3981. const mediumSeverityText = issues.medium.length
  3982. ? common_1.colorTextBySeverity(common_1.SEVERITY.MEDIUM, ` ${issues.medium.length} [Medium] `)
  3983. : '';
  3984. const highSeverityText = issues.high.length
  3985. ? common_1.colorTextBySeverity(common_1.SEVERITY.HIGH, ` ${issues.high.length} [High] `)
  3986. : '';
  3987. const codeIssueCount = issues.low.length + issues.medium.length + issues.high.length;
  3988. const codeIssueFound = ` ${codeIssueCount} Code issue${codeIssueCount > 0 ? 's' : ''} found`;
  3989. const issuesBySeverityText = highSeverityText + mediumSeverityText + lowSeverityText;
  3990. const vulnPathsText = theme_1.color.status.success(`${theme_1.icon.VALID} Awesome! No issues were found.`);
  3991. return codeIssueCount > 0
  3992. ? codeIssueFound + '\n' + issuesBySeverityText
  3993. : vulnPathsText;
  3994. }
  3995. function getIssues(results, rulesMap) {
  3996. const issuesInit = {
  3997. low: [],
  3998. medium: [],
  3999. high: [],
  4000. };
  4001. const issues = results.reduce((acc, res) => {
  4002. var _a, _b;
  4003. if ((_a = res.locations) === null || _a === void 0 ? void 0 : _a.length) {
  4004. const location = res.locations[0].physicalLocation;
  4005. if (res.level && (location === null || location === void 0 ? void 0 : location.artifactLocation) && (location === null || location === void 0 ? void 0 : location.region)) {
  4006. const severity = sarifToSeverityLevel(res.level);
  4007. const ruleId = res.ruleId;
  4008. if (!(ruleId in rulesMap)) {
  4009. debug('Rule ID does not exist in the rules list');
  4010. }
  4011. const ruleName = ((_b = rulesMap[ruleId].shortDescription) === null || _b === void 0 ? void 0 : _b.text) ||
  4012. rulesMap[ruleId].name ||
  4013. '';
  4014. const ruleIdSeverityText = common_1.colorTextBySeverity(severity, ` ${theme_1.icon.ISSUE} [${severity}] ${chalk_1.default.bold(ruleName)}`);
  4015. const artifactLocationUri = location.artifactLocation.uri;
  4016. const startLine = location.region.startLine;
  4017. const text = res.message.text;
  4018. const title = ruleIdSeverityText;
  4019. const path = ` Path: ${artifactLocationUri}, line ${startLine}`;
  4020. const info = ` Info: ${text}`;
  4021. acc[severity.toLowerCase()].push(`${title} \n ${path} \n ${info}\n\n`);
  4022. }
  4023. }
  4024. return acc;
  4025. }, issuesInit);
  4026. return issues;
  4027. }
  4028. function getRulesMap(rules) {
  4029. const rulesMapByID = rules.reduce((acc, rule) => {
  4030. acc[rule.id] = rule;
  4031. return acc;
  4032. }, {});
  4033. return rulesMapByID;
  4034. }
  4035. function sarifToSeverityLevel(sarifConfigurationLevel) {
  4036. const severityLevel = {
  4037. note: 'Low',
  4038. warning: 'Medium',
  4039. error: 'High',
  4040. };
  4041. return severityLevel[sarifConfigurationLevel];
  4042. }
  4043. function getMeta(options, path) {
  4044. const padToLength = 19; // chars to align
  4045. const orgName = options.org || '';
  4046. const projectPath = options.path || path;
  4047. const meta = [
  4048. right_pad_1.rightPadWithSpaces('Organization: ', padToLength) + chalk_1.default.bold(orgName),
  4049. ];
  4050. meta.push(right_pad_1.rightPadWithSpaces('Test type: ', padToLength) +
  4051. chalk_1.default.bold('Static code analysis'));
  4052. meta.push(right_pad_1.rightPadWithSpaces('Project path: ', padToLength) + chalk_1.default.bold(projectPath));
  4053. return meta.join('\n');
  4054. }
  4055. exports.getMeta = getMeta;
  4056. function getPrefix(path) {
  4057. return chalk_1.default.bold.white('\nTesting ' + path + ' ...\n\n');
  4058. }
  4059. exports.getPrefix = getPrefix;
  4060. /***/ }),
  4061. /***/ 93221:
  4062. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4063. "use strict";
  4064. Object.defineProperty(exports, "__esModule", ({ value: true }));
  4065. exports.codePlugin = void 0;
  4066. const chalk_1 = __webpack_require__(32589);
  4067. const debugLib = __webpack_require__(15158);
  4068. const uuid_1 = __webpack_require__(42277);
  4069. const analysis_1 = __webpack_require__(2806);
  4070. const settings_1 = __webpack_require__(24930);
  4071. const output_format_1 = __webpack_require__(75802);
  4072. const errors_1 = __webpack_require__(55191);
  4073. const json_1 = __webpack_require__(27019);
  4074. const analytics = __webpack_require__(82744);
  4075. const debug = debugLib('snyk-code');
  4076. exports.codePlugin = {
  4077. // We currently don't use scan/display. we will need to consolidate ecosystem plugins
  4078. // to accept flows that act differently in the `testDependencies` step, as we have here
  4079. async scan() {
  4080. return null;
  4081. },
  4082. async display() {
  4083. return '';
  4084. },
  4085. async test(paths, options) {
  4086. var _a, _b, _c, _d;
  4087. const requestId = uuid_1.v4();
  4088. debug(`Request ID: ${requestId}`);
  4089. try {
  4090. analytics.add('sast-scan', true);
  4091. const sastSettings = await settings_1.getSastSettings(options);
  4092. // Currently code supports only one path
  4093. const path = paths[0];
  4094. const sarifTypedResult = await analysis_1.getCodeAnalysisAndParseResults(path, options, sastSettings, requestId);
  4095. if (!sarifTypedResult) {
  4096. throw new errors_1.NoSupportedSastFiles();
  4097. }
  4098. const numOfIssues = ((_b = (_a = sarifTypedResult.runs) === null || _a === void 0 ? void 0 : _a[0].results) === null || _b === void 0 ? void 0 : _b.length) || 0;
  4099. analytics.add('sast-issues-found', numOfIssues);
  4100. let newOrg = options.org;
  4101. if (!newOrg && sastSettings.org) {
  4102. newOrg = sastSettings.org;
  4103. }
  4104. const meta = output_format_1.getMeta({ ...options, org: newOrg }, path);
  4105. const prefix = output_format_1.getPrefix(path);
  4106. let readableResult = output_format_1.getCodeDisplayedOutput(sarifTypedResult, meta, prefix);
  4107. if (numOfIssues > 0 && options['no-markdown']) {
  4108. (_d = (_c = sarifTypedResult.runs) === null || _c === void 0 ? void 0 : _c[0].results) === null || _d === void 0 ? void 0 : _d.forEach(({ message }) => {
  4109. delete message.markdown;
  4110. });
  4111. }
  4112. let sarifResult;
  4113. if (options['sarif-file-output']) {
  4114. sarifResult = json_1.jsonStringifyLargeObject(sarifTypedResult);
  4115. }
  4116. let jsonResult;
  4117. if (options['json-file-output']) {
  4118. jsonResult = json_1.jsonStringifyLargeObject(sarifTypedResult);
  4119. }
  4120. if (options.sarif || options.json) {
  4121. readableResult = json_1.jsonStringifyLargeObject(sarifTypedResult);
  4122. }
  4123. if (numOfIssues > 0) {
  4124. throwIssuesError({ readableResult, sarifResult, jsonResult });
  4125. }
  4126. return sarifResult ? { readableResult, sarifResult } : { readableResult };
  4127. }
  4128. catch (error) {
  4129. let err;
  4130. if (isCodeClientError(error)) {
  4131. const isUnauthorized = isUnauthorizedError(error)
  4132. ? 'Unauthorized: '
  4133. : '';
  4134. err = new errors_1.FailedToRunTestError(`${isUnauthorized}Failed to run 'code test'`, error.statusCode);
  4135. }
  4136. else if (error instanceof Error) {
  4137. err = error;
  4138. }
  4139. else if (isUnauthorizedError(error)) {
  4140. err = new errors_1.FailedToRunTestError(error.message, error.code);
  4141. }
  4142. else {
  4143. err = new Error(error);
  4144. }
  4145. debug(chalk_1.default.bold.red(`requestId: ${requestId} statusCode:${error.code ||
  4146. error.statusCode}, message: ${error.statusText || error.message}`));
  4147. throw err;
  4148. }
  4149. },
  4150. };
  4151. function isCodeClientError(error) {
  4152. return (error.hasOwnProperty('statusCode') &&
  4153. error.hasOwnProperty('statusText') &&
  4154. error.hasOwnProperty('apiName'));
  4155. }
  4156. function isUnauthorizedError(error) {
  4157. return (error.statusCode === 401 ||
  4158. error.statusCode === 403 ||
  4159. error.code === 403 ||
  4160. error.code === 401);
  4161. }
  4162. function throwIssuesError(args) {
  4163. const err = new Error(args.readableResult);
  4164. err.code = 'VULNS';
  4165. if (args.sarifResult !== undefined) {
  4166. err.sarifStringifiedResults = args.sarifResult;
  4167. }
  4168. if (args.jsonResult !== undefined) {
  4169. err.jsonStringifiedResults = args.jsonResult;
  4170. }
  4171. throw err;
  4172. }
  4173. /***/ }),
  4174. /***/ 24930:
  4175. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4176. "use strict";
  4177. Object.defineProperty(exports, "__esModule", ({ value: true }));
  4178. exports.getSastSettings = void 0;
  4179. const config_1 = __webpack_require__(25425);
  4180. const checks_1 = __webpack_require__(15976);
  4181. const errors_1 = __webpack_require__(55191);
  4182. async function getSastSettings(options) {
  4183. const org = options.org || config_1.default.org;
  4184. // This is an unexpected path, code plugin executed for non-code command.
  4185. if (!options.code) {
  4186. throw new errors_1.FeatureNotSupportedForOrgError(org);
  4187. }
  4188. const sastSettingsResponse = await checks_1.getSastSettingsForOrg(org);
  4189. if ((sastSettingsResponse === null || sastSettingsResponse === void 0 ? void 0 : sastSettingsResponse.code) === 401 ||
  4190. (sastSettingsResponse === null || sastSettingsResponse === void 0 ? void 0 : sastSettingsResponse.code) === 403) {
  4191. throw errors_1.AuthFailedError(sastSettingsResponse.error, sastSettingsResponse.code);
  4192. }
  4193. if ((sastSettingsResponse === null || sastSettingsResponse === void 0 ? void 0 : sastSettingsResponse.code) === 404) {
  4194. throw new errors_1.NotFoundError(sastSettingsResponse === null || sastSettingsResponse === void 0 ? void 0 : sastSettingsResponse.userMessage);
  4195. }
  4196. if (!sastSettingsResponse.sastEnabled) {
  4197. throw new errors_1.FeatureNotSupportedForOrgError(org, 'Snyk Code', 'enable in Settings > Snyk Code');
  4198. }
  4199. const trackUsageResponse = await checks_1.trackUsage(org);
  4200. if (trackUsageResponse.code === 429) {
  4201. throw new errors_1.FailedToRunTestError(trackUsageResponse.userMessage, trackUsageResponse.code);
  4202. }
  4203. return sastSettingsResponse;
  4204. }
  4205. exports.getSastSettings = getSastSettings;
  4206. /***/ }),
  4207. /***/ 33113:
  4208. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4209. "use strict";
  4210. Object.defineProperty(exports, "__esModule", ({ value: true }));
  4211. var testEmitter_1 = __webpack_require__(83901);
  4212. Object.defineProperty(exports, "analysisProgressUpdate", ({ enumerable: true, get: function () { return testEmitter_1.analysisProgressUpdate; } }));
  4213. /***/ }),
  4214. /***/ 83901:
  4215. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4216. "use strict";
  4217. Object.defineProperty(exports, "__esModule", ({ value: true }));
  4218. exports.analysisProgressUpdate = void 0;
  4219. const code_client_1 = __webpack_require__(95951);
  4220. const spinner_1 = __webpack_require__(86766);
  4221. const debugLib = __webpack_require__(15158);
  4222. function analysisProgressUpdate() {
  4223. let currentMessage = '';
  4224. const showSpinner = (message) => {
  4225. if (currentMessage === message)
  4226. return;
  4227. spinner_1.spinner.clear(currentMessage)();
  4228. currentMessage = message;
  4229. return spinner_1.spinner(message);
  4230. };
  4231. code_client_1.emitter.on('supportedFilesLoaded', () => showSpinner(`Supported extensions loaded`));
  4232. code_client_1.emitter.on('scanFilesProgress', (processed) => showSpinner(`Scanning files: ${Math.round(processed / 100)}00`));
  4233. code_client_1.emitter.on('createBundleProgress', (processed, total) => showSpinner(`Batching file upload: ${processed} / ${total}`));
  4234. code_client_1.emitter.on('uploadBundleProgress', (processed, total) => showSpinner(`Upload progress: ${processed} / ${total}`));
  4235. code_client_1.emitter.on('analyseProgress', (data) => showSpinner(`${data.status}: ${Math.round(data.progress * 100)}%`));
  4236. code_client_1.emitter.on('sendError', (error) => {
  4237. throw error;
  4238. });
  4239. code_client_1.emitter.on('apiRequestLog', (data) => {
  4240. const debug = debugLib('snyk-code');
  4241. debug('---> API request log ', data);
  4242. });
  4243. }
  4244. exports.analysisProgressUpdate = analysisProgressUpdate;
  4245. /***/ }),
  4246. /***/ 8820:
  4247. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4248. "use strict";
  4249. Object.defineProperty(exports, "__esModule", ({ value: true }));
  4250. exports.findAndLoadPolicy = void 0;
  4251. const snykPolicyLib = __webpack_require__(70535);
  4252. const debugModule = __webpack_require__(15158);
  4253. const _1 = __webpack_require__(32615);
  4254. const analytics = __webpack_require__(82744);
  4255. const debug = debugModule('snyk');
  4256. async function findAndLoadPolicy(root, scanType, options, pkg, scannedProjectFolder) {
  4257. const isDocker = scanType === 'docker';
  4258. const isNodeProject = ['npm', 'yarn'].includes(scanType);
  4259. // monitor
  4260. let policyLocations = [
  4261. options['policy-path'] || scannedProjectFolder || root,
  4262. ];
  4263. if (isDocker) {
  4264. policyLocations = policyLocations.filter((loc) => loc !== root);
  4265. }
  4266. else if (isNodeProject) {
  4267. // TODO: pluckPolicies expects a package.json object to
  4268. // find and apply policies in node_modules
  4269. policyLocations = policyLocations.concat(_1.pluckPolicies(pkg));
  4270. }
  4271. debug('Potential policy locations found:', policyLocations);
  4272. analytics.add('policies', policyLocations.length);
  4273. analytics.add('policyLocations', policyLocations);
  4274. if (policyLocations.length === 0) {
  4275. return;
  4276. }
  4277. let policy;
  4278. try {
  4279. policy = await snykPolicyLib.load(policyLocations, options);
  4280. }
  4281. catch (err) {
  4282. // note: inline catch, to handle error from .load
  4283. // if the .snyk file wasn't found, it is fine
  4284. if (err.code !== 'ENOENT' && err.code !== 'ENOTDIR') {
  4285. throw err;
  4286. }
  4287. }
  4288. return policy;
  4289. }
  4290. exports.findAndLoadPolicy = findAndLoadPolicy;
  4291. /***/ }),
  4292. /***/ 32615:
  4293. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4294. "use strict";
  4295. Object.defineProperty(exports, "__esModule", ({ value: true }));
  4296. var pluck_policies_1 = __webpack_require__(68247);
  4297. Object.defineProperty(exports, "pluckPolicies", ({ enumerable: true, get: function () { return pluck_policies_1.pluckPolicies; } }));
  4298. var find_and_load_policy_1 = __webpack_require__(8820);
  4299. Object.defineProperty(exports, "findAndLoadPolicy", ({ enumerable: true, get: function () { return find_and_load_policy_1.findAndLoadPolicy; } }));
  4300. /***/ }),
  4301. /***/ 68247:
  4302. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4303. "use strict";
  4304. Object.defineProperty(exports, "__esModule", ({ value: true }));
  4305. exports.pluckPolicies = void 0;
  4306. const flatten = __webpack_require__(5800);
  4307. function pluckPolicies(pkg) {
  4308. if (!pkg) {
  4309. return [];
  4310. }
  4311. if (pkg.snyk) {
  4312. return pkg.snyk;
  4313. }
  4314. if (!pkg.dependencies) {
  4315. return [];
  4316. }
  4317. return flatten(Object.keys(pkg.dependencies)
  4318. .map((name) => pluckPolicies(pkg.dependencies[name]))
  4319. .filter(Boolean));
  4320. }
  4321. exports.pluckPolicies = pluckPolicies;
  4322. /***/ }),
  4323. /***/ 74434:
  4324. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4325. "use strict";
  4326. Object.defineProperty(exports, "__esModule", ({ value: true }));
  4327. exports.handleProcessingStatus = exports.extractResolutionMetaFromScanResult = exports.delayNextStep = void 0;
  4328. const common_1 = __webpack_require__(70527);
  4329. const errors_1 = __webpack_require__(55191);
  4330. async function delayNextStep(attemptsCount, maxAttempts, pollInterval) {
  4331. attemptsCount++;
  4332. checkPollingAttempts(maxAttempts)(attemptsCount);
  4333. await common_1.sleep(pollInterval);
  4334. }
  4335. exports.delayNextStep = delayNextStep;
  4336. function checkPollingAttempts(maxAttempts) {
  4337. return (attemptsCount) => {
  4338. if (attemptsCount > maxAttempts) {
  4339. throw new Error('Exceeded Polling maxAttempts');
  4340. }
  4341. };
  4342. }
  4343. function extractResolutionMetaFromScanResult({ name, target, identity, policy, targetReference, }) {
  4344. return {
  4345. name,
  4346. target,
  4347. identity,
  4348. policy,
  4349. targetReference,
  4350. };
  4351. }
  4352. exports.extractResolutionMetaFromScanResult = extractResolutionMetaFromScanResult;
  4353. function handleProcessingStatus(response) {
  4354. if ((response === null || response === void 0 ? void 0 : response.status) === 'CANCELLED' || (response === null || response === void 0 ? void 0 : response.status) === 'ERROR') {
  4355. throw new errors_1.FailedToRunTestError('Failed to process the project. Please run the command again with the `-d` flag and contact support@snyk.io with the contents of the output');
  4356. }
  4357. }
  4358. exports.handleProcessingStatus = handleProcessingStatus;
  4359. /***/ }),
  4360. /***/ 59354:
  4361. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4362. "use strict";
  4363. Object.defineProperty(exports, "__esModule", ({ value: true }));
  4364. exports.pollingMonitorWithTokenUntilDone = exports.requestMonitorPollingToken = void 0;
  4365. const config_1 = __webpack_require__(25425);
  4366. const is_ci_1 = __webpack_require__(10090);
  4367. const promise_1 = __webpack_require__(90430);
  4368. const common_1 = __webpack_require__(53110);
  4369. const api_token_1 = __webpack_require__(95181);
  4370. const common_2 = __webpack_require__(74434);
  4371. const monitor_1 = __webpack_require__(3708);
  4372. async function requestMonitorPollingToken(options, isAsync, scanResult) {
  4373. if ((scanResult === null || scanResult === void 0 ? void 0 : scanResult.target) && scanResult.target['remoteUrl'] === '') {
  4374. scanResult.target['remoteUrl'] = scanResult.name;
  4375. }
  4376. const payload = {
  4377. method: 'PUT',
  4378. url: `${config_1.default.API}/monitor-dependencies`,
  4379. json: true,
  4380. headers: {
  4381. 'x-is-ci': is_ci_1.isCI(),
  4382. authorization: api_token_1.getAuthHeader(),
  4383. },
  4384. body: {
  4385. isAsync,
  4386. scanResult,
  4387. method: 'cli',
  4388. },
  4389. qs: { ...common_1.assembleQueryString(options) },
  4390. };
  4391. return await promise_1.makeRequest(payload);
  4392. }
  4393. exports.requestMonitorPollingToken = requestMonitorPollingToken;
  4394. async function pollingMonitorWithTokenUntilDone(token, isAsync, options, pollInterval, attemptsCount, maxAttempts = Infinity, resolutionMeta, contributors = []) {
  4395. const payload = {
  4396. method: 'PUT',
  4397. url: `${config_1.default.API}/monitor-dependencies/${token}`,
  4398. json: true,
  4399. headers: {
  4400. 'x-is-ci': is_ci_1.isCI(),
  4401. authorization: api_token_1.getAuthHeader(),
  4402. },
  4403. qs: { ...common_1.assembleQueryString(options) },
  4404. body: {
  4405. isAsync,
  4406. resolutionMeta,
  4407. contributors,
  4408. method: 'cli',
  4409. tags: monitor_1.generateTags(options),
  4410. attributes: monitor_1.generateProjectAttributes(options),
  4411. projectName: (resolutionMeta === null || resolutionMeta === void 0 ? void 0 : resolutionMeta.name) || options['project-name'] || config_1.default.PROJECT_NAME,
  4412. },
  4413. };
  4414. const response = await promise_1.makeRequest(payload);
  4415. common_2.handleProcessingStatus(response);
  4416. if (response.ok && response.isMonitored) {
  4417. return response;
  4418. }
  4419. await common_2.delayNextStep(attemptsCount, maxAttempts, pollInterval);
  4420. return await pollingMonitorWithTokenUntilDone(token, isAsync, options, pollInterval, attemptsCount, maxAttempts, resolutionMeta, contributors);
  4421. }
  4422. exports.pollingMonitorWithTokenUntilDone = pollingMonitorWithTokenUntilDone;
  4423. /***/ }),
  4424. /***/ 77584:
  4425. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4426. "use strict";
  4427. Object.defineProperty(exports, "__esModule", ({ value: true }));
  4428. exports.pollingTestWithTokenUntilDone = exports.requestTestPollingToken = void 0;
  4429. const config_1 = __webpack_require__(25425);
  4430. const is_ci_1 = __webpack_require__(10090);
  4431. const promise_1 = __webpack_require__(90430);
  4432. const common_1 = __webpack_require__(53110);
  4433. const api_token_1 = __webpack_require__(95181);
  4434. const common_2 = __webpack_require__(74434);
  4435. async function requestTestPollingToken(options, isAsync, scanResult) {
  4436. const payload = {
  4437. method: 'POST',
  4438. url: `${config_1.default.API}/test-dependencies`,
  4439. json: true,
  4440. headers: {
  4441. 'x-is-ci': is_ci_1.isCI(),
  4442. authorization: api_token_1.getAuthHeader(),
  4443. },
  4444. body: {
  4445. isAsync,
  4446. scanResult,
  4447. },
  4448. qs: common_1.assembleQueryString(options),
  4449. };
  4450. return await promise_1.makeRequest(payload);
  4451. }
  4452. exports.requestTestPollingToken = requestTestPollingToken;
  4453. async function pollingTestWithTokenUntilDone(token, type, options, pollInterval, attemptsCount, maxAttempts = Infinity) {
  4454. const payload = {
  4455. method: 'GET',
  4456. url: `${config_1.default.API}/test-dependencies/${token}`,
  4457. json: true,
  4458. headers: {
  4459. 'x-is-ci': is_ci_1.isCI(),
  4460. authorization: api_token_1.getAuthHeader(),
  4461. },
  4462. qs: { ...common_1.assembleQueryString(options), type },
  4463. };
  4464. const response = await promise_1.makeRequest(payload);
  4465. common_2.handleProcessingStatus(response);
  4466. if (response.result) {
  4467. const { issues, issuesData, depGraphData, depsFilePaths, fileSignaturesDetails, vulnerabilities, path, dependencyCount, packageManager, } = response.result;
  4468. return {
  4469. issues,
  4470. issuesData,
  4471. depGraphData,
  4472. depsFilePaths,
  4473. fileSignaturesDetails,
  4474. vulnerabilities,
  4475. path,
  4476. dependencyCount,
  4477. packageManager,
  4478. };
  4479. }
  4480. await common_2.delayNextStep(attemptsCount, maxAttempts, pollInterval);
  4481. return await pollingTestWithTokenUntilDone(token, type, options, pollInterval, attemptsCount, maxAttempts);
  4482. }
  4483. exports.pollingTestWithTokenUntilDone = pollingTestWithTokenUntilDone;
  4484. /***/ }),
  4485. /***/ 79792:
  4486. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4487. "use strict";
  4488. Object.defineProperty(exports, "__esModule", ({ value: true }));
  4489. exports.maybePrintDepTree = exports.maybePrintDepGraph = void 0;
  4490. const config_1 = __webpack_require__(25425);
  4491. const depGraphLib = __webpack_require__(71479);
  4492. const utils_1 = __webpack_require__(61721);
  4493. const json_1 = __webpack_require__(27019);
  4494. async function maybePrintDepGraph(options, depGraph) {
  4495. // TODO @boost: remove this logic once we get a valid depGraph print format
  4496. const graphPathsCount = utils_1.countPathsToGraphRoot(depGraph);
  4497. const hasTooManyPaths = graphPathsCount > config_1.default.PRUNE_DEPS_THRESHOLD;
  4498. if (!hasTooManyPaths) {
  4499. const depTree = (await depGraphLib.legacy.graphToDepTree(depGraph, depGraph.pkgManager.name));
  4500. maybePrintDepTree(options, depTree);
  4501. }
  4502. else {
  4503. if (options['print-deps']) {
  4504. if (options.json) {
  4505. console.warn('--print-deps --json option not yet supported for large projects. Displaying graph json output instead');
  4506. // TODO @boost: add as output graphviz 'dot' file to visualize?
  4507. console.log(json_1.jsonStringifyLargeObject(depGraph.toJSON()));
  4508. }
  4509. else {
  4510. console.warn('--print-deps option not yet supported for large projects. Try with --json.');
  4511. }
  4512. }
  4513. }
  4514. }
  4515. exports.maybePrintDepGraph = maybePrintDepGraph;
  4516. // This option is still experimental and might be deprecated.
  4517. // It might be a better idea to convert it to a command (i.e. do not perform test/monitor).
  4518. function maybePrintDepTree(options, rootPackage) {
  4519. if (options['print-deps']) {
  4520. if (options.json) {
  4521. // Will produce 2 JSON outputs, one for the deps, one for the vuln scan.
  4522. console.log(json_1.jsonStringifyLargeObject(rootPackage));
  4523. }
  4524. else {
  4525. printDepsForTree({ [rootPackage.name]: rootPackage });
  4526. }
  4527. }
  4528. }
  4529. exports.maybePrintDepTree = maybePrintDepTree;
  4530. function printDepsForTree(depDict, prefix = '') {
  4531. let counter = 0;
  4532. const keys = Object.keys(depDict);
  4533. for (const name of keys) {
  4534. const dep = depDict[name];
  4535. let branch = '├─ ';
  4536. const last = counter === keys.length - 1;
  4537. if (last) {
  4538. branch = '└─ ';
  4539. }
  4540. console.log(prefix +
  4541. (prefix ? branch : '') +
  4542. dep.name +
  4543. ' @ ' +
  4544. (dep.version ? dep.version : ''));
  4545. if (dep.dependencies) {
  4546. printDepsForTree(dep.dependencies, prefix + (last ? ' ' : '│ '));
  4547. }
  4548. counter++;
  4549. }
  4550. }
  4551. /***/ }),
  4552. /***/ 3594:
  4553. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4554. "use strict";
  4555. Object.defineProperty(exports, "__esModule", ({ value: true }));
  4556. exports.getInfo = void 0;
  4557. const gitTargetBuilder = __webpack_require__(24850);
  4558. const containerTargetBuilder = __webpack_require__(57493);
  4559. const invalid_remote_url_error_1 = __webpack_require__(86033);
  4560. const TARGET_BUILDERS = [containerTargetBuilder, gitTargetBuilder];
  4561. async function getInfo(scannedProject, options, packageInfo) {
  4562. const isFromContainer = options.docker || options.isDocker || false;
  4563. for (const builder of TARGET_BUILDERS) {
  4564. const target = await builder.getInfo({
  4565. isFromContainer,
  4566. scannedProject,
  4567. packageInfo,
  4568. });
  4569. if (target) {
  4570. const remoteUrl = options['remote-repo-url'];
  4571. if (!remoteUrl) {
  4572. return target;
  4573. }
  4574. if (typeof remoteUrl !== 'string') {
  4575. throw new invalid_remote_url_error_1.InvalidRemoteUrlError();
  4576. }
  4577. return { ...target, remoteUrl };
  4578. }
  4579. }
  4580. return null;
  4581. }
  4582. exports.getInfo = getInfo;
  4583. /***/ }),
  4584. /***/ 57493:
  4585. /***/ ((__unused_webpack_module, exports) => {
  4586. "use strict";
  4587. Object.defineProperty(exports, "__esModule", ({ value: true }));
  4588. exports.getInfo = void 0;
  4589. async function getInfo({ isFromContainer, scannedProject, packageInfo, }) {
  4590. var _a;
  4591. // safety check
  4592. if (!isFromContainer) {
  4593. return null;
  4594. }
  4595. const imageNameOnProjectMeta = scannedProject.meta && scannedProject.meta.imageName;
  4596. return {
  4597. image: imageNameOnProjectMeta || ((_a = packageInfo) === null || _a === void 0 ? void 0 : _a.image) || (packageInfo === null || packageInfo === void 0 ? void 0 : packageInfo.name),
  4598. };
  4599. }
  4600. exports.getInfo = getInfo;
  4601. /***/ }),
  4602. /***/ 24850:
  4603. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4604. "use strict";
  4605. Object.defineProperty(exports, "__esModule", ({ value: true }));
  4606. exports.getInfo = void 0;
  4607. const url = __webpack_require__(78835);
  4608. const subProcess = __webpack_require__(66487);
  4609. // for scp-like syntax [user@]server:project.git
  4610. const originRegex = /(.+@)?(.+):(.+$)/;
  4611. async function getInfo({ isFromContainer, cwd, }) {
  4612. // safety check
  4613. if (isFromContainer) {
  4614. return null;
  4615. }
  4616. const target = {};
  4617. try {
  4618. const origin = (await subProcess.execute('git', ['remote', 'get-url', 'origin'], { cwd })).trim();
  4619. if (origin) {
  4620. const { protocol, host, pathname = '' } = url.parse(origin);
  4621. // Not handling git:// as it has no connection options
  4622. if (host && protocol && ['ssh:', 'http:', 'https:'].includes(protocol)) {
  4623. // same format for parseable URLs
  4624. target.remoteUrl = `http://${host}${pathname}`;
  4625. }
  4626. else {
  4627. const originRes = originRegex.exec(origin);
  4628. if (originRes && originRes[2] && originRes[3]) {
  4629. target.remoteUrl = `http://${originRes[2]}/${originRes[3]}`;
  4630. }
  4631. else {
  4632. // else keep the original
  4633. target.remoteUrl = origin;
  4634. }
  4635. }
  4636. }
  4637. }
  4638. catch (err) {
  4639. // Swallowing exception since we don't want to break the monitor if there is a problem
  4640. // executing git commands.
  4641. }
  4642. try {
  4643. target.branch = (await subProcess.execute('git', ['rev-parse', '--abbrev-ref', 'HEAD'], {
  4644. cwd,
  4645. })).trim();
  4646. }
  4647. catch (err) {
  4648. // Swallowing exception since we don't want to break the monitor if there is a problem
  4649. // executing git commands.
  4650. }
  4651. return target;
  4652. }
  4653. exports.getInfo = getInfo;
  4654. /***/ }),
  4655. /***/ 39409:
  4656. /***/ ((__unused_webpack_module, exports) => {
  4657. "use strict";
  4658. Object.defineProperty(exports, "__esModule", ({ value: true }));
  4659. exports.isGitTarget = void 0;
  4660. function isGitTarget(target) {
  4661. return target && (target.branch || target.remoteUrl);
  4662. }
  4663. exports.isGitTarget = isGitTarget;
  4664. /***/ }),
  4665. /***/ 87725:
  4666. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4667. "use strict";
  4668. Object.defineProperty(exports, "__esModule", ({ value: true }));
  4669. exports.pruneGraph = void 0;
  4670. const _debug = __webpack_require__(15158);
  4671. const dep_graph_1 = __webpack_require__(71479);
  4672. const config_1 = __webpack_require__(25425);
  4673. const errors_1 = __webpack_require__(55191);
  4674. const analytics = __webpack_require__(82744);
  4675. const utils_1 = __webpack_require__(61721);
  4676. const debug = _debug('snyk:prune');
  4677. const { depTreeToGraph, graphToDepTree } = dep_graph_1.legacy;
  4678. async function pruneGraph(depGraph, packageManager, pruneIsRequired = false) {
  4679. const prePrunePathsCount = utils_1.countPathsToGraphRoot(depGraph);
  4680. const isDenseGraph = prePrunePathsCount > config_1.default.PRUNE_DEPS_THRESHOLD;
  4681. debug('rootPkg', depGraph.rootPkg);
  4682. debug('prePrunePathsCount: ' + prePrunePathsCount);
  4683. debug('isDenseGraph', isDenseGraph);
  4684. analytics.add('prePrunedPathsCount', prePrunePathsCount);
  4685. if (isDenseGraph || pruneIsRequired) {
  4686. debug('Trying to prune the graph');
  4687. const pruneStartTime = Date.now();
  4688. const prunedTree = (await graphToDepTree(depGraph, packageManager, {
  4689. deduplicateWithinTopLevelDeps: true,
  4690. }));
  4691. const graphToTreeEndTime = Date.now();
  4692. analytics.add('prune.graphToTreeDuration', graphToTreeEndTime - pruneStartTime);
  4693. const prunedGraph = await depTreeToGraph(prunedTree, packageManager);
  4694. analytics.add('prune.treeToGraphDuration', Date.now() - graphToTreeEndTime);
  4695. const postPrunePathsCount = utils_1.countPathsToGraphRoot(prunedGraph);
  4696. analytics.add('postPrunedPathsCount', postPrunePathsCount);
  4697. debug('postPrunePathsCount' + postPrunePathsCount);
  4698. if (postPrunePathsCount > config_1.default.MAX_PATH_COUNT) {
  4699. debug('Too many paths to process the project');
  4700. //TODO replace the throw below with TooManyPaths we do not calculate vuln paths there
  4701. throw new errors_1.TooManyVulnPaths();
  4702. }
  4703. return prunedGraph;
  4704. }
  4705. return depGraph;
  4706. }
  4707. exports.pruneGraph = pruneGraph;
  4708. /***/ }),
  4709. /***/ 90430:
  4710. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4711. "use strict";
  4712. Object.defineProperty(exports, "__esModule", ({ value: true }));
  4713. exports.makeRequestRest = exports.makeRequest = void 0;
  4714. const api_token_1 = __webpack_require__(95181);
  4715. const request = __webpack_require__(52050);
  4716. async function makeRequest(payload) {
  4717. return new Promise((resolve, reject) => {
  4718. request.makeRequest(payload, (error, res, body) => {
  4719. if (error) {
  4720. return reject(error);
  4721. }
  4722. if (res.statusCode !== 200) {
  4723. return reject({
  4724. code: res.statusCode,
  4725. message: body === null || body === void 0 ? void 0 : body.message,
  4726. });
  4727. }
  4728. resolve(body);
  4729. });
  4730. });
  4731. }
  4732. exports.makeRequest = makeRequest;
  4733. /**
  4734. * All rest request will essentially be the same and are JSON by default
  4735. * Thus if no headers provided default headers are used
  4736. * @param {any} payload for the request
  4737. * @returns
  4738. */
  4739. async function makeRequestRest(payload) {
  4740. return new Promise((resolve, reject) => {
  4741. var _a;
  4742. payload.headers = (_a = payload.headers) !== null && _a !== void 0 ? _a : {
  4743. 'Content-Type': 'application/vnd.api+json',
  4744. authorization: api_token_1.getAuthHeader(),
  4745. };
  4746. payload.json = true;
  4747. request.makeRequest(payload, (error, res, body) => {
  4748. if (error) {
  4749. return reject(error);
  4750. }
  4751. if (res.statusCode >= 400) {
  4752. return reject({
  4753. code: res.statusCode,
  4754. body: JSON.parse(body),
  4755. });
  4756. }
  4757. resolve(JSON.parse(body));
  4758. });
  4759. });
  4760. }
  4761. exports.makeRequestRest = makeRequestRest;
  4762. /***/ }),
  4763. /***/ 80627:
  4764. /***/ ((__unused_webpack_module, exports) => {
  4765. "use strict";
  4766. Object.defineProperty(exports, "__esModule", ({ value: true }));
  4767. exports.rightPadWithSpaces = void 0;
  4768. function rightPadWithSpaces(s, padding) {
  4769. const padLength = padding - s.length;
  4770. if (padLength <= 0) {
  4771. return s;
  4772. }
  4773. return s + ' '.repeat(padLength);
  4774. }
  4775. exports.rightPadWithSpaces = rightPadWithSpaces;
  4776. /***/ }),
  4777. /***/ 38080:
  4778. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4779. "use strict";
  4780. Object.defineProperty(exports, "__esModule", ({ value: true }));
  4781. exports.assembleEcosystemPayloads = void 0;
  4782. const path = __webpack_require__(85622);
  4783. const config_1 = __webpack_require__(25425);
  4784. const is_ci_1 = __webpack_require__(10090);
  4785. const ecosystems_1 = __webpack_require__(5168);
  4786. const common_1 = __webpack_require__(53110);
  4787. const spinner_1 = __webpack_require__(86766);
  4788. const policy_1 = __webpack_require__(4669);
  4789. const api_token_1 = __webpack_require__(95181);
  4790. const errors_1 = __webpack_require__(55191);
  4791. async function assembleEcosystemPayloads(ecosystem, options) {
  4792. // For --all-projects packageManager is yet undefined here. Use 'all'
  4793. let analysisTypeText = 'all dependencies for ';
  4794. if (options.docker) {
  4795. analysisTypeText = 'container dependencies for ';
  4796. }
  4797. else if (options.packageManager) {
  4798. analysisTypeText = options.packageManager + ' dependencies for ';
  4799. }
  4800. const spinnerLbl = 'Analyzing ' +
  4801. analysisTypeText +
  4802. (path.relative('.', path.join(options.path, options.file || '')) ||
  4803. path.relative('..', '.') + ' project dir');
  4804. spinner_1.spinner.clear(spinnerLbl)();
  4805. if (!options.quiet) {
  4806. await spinner_1.spinner(spinnerLbl);
  4807. }
  4808. try {
  4809. const plugin = ecosystems_1.getPlugin(ecosystem);
  4810. const pluginResponse = await plugin.scan(options);
  4811. const payloads = [];
  4812. // TODO: This is a temporary workaround until the plugins themselves can read policy files and set names!
  4813. for (const scanResult of pluginResponse.scanResults) {
  4814. // WARNING! This mutates the payload. Policy logic should be in the plugin.
  4815. const policy = await policy_1.findAndLoadPolicyForScanResult(scanResult, options);
  4816. if (policy !== undefined) {
  4817. scanResult.policy = policy.toString();
  4818. }
  4819. // WARNING! This mutates the payload. The project name logic should be handled in the plugin.
  4820. scanResult.name =
  4821. options['project-name'] || config_1.default.PROJECT_NAME || scanResult.name;
  4822. payloads.push({
  4823. method: 'POST',
  4824. url: `${config_1.default.API}${options.testDepGraphDockerEndpoint ||
  4825. '/test-dependencies'}`,
  4826. json: true,
  4827. headers: {
  4828. 'x-is-ci': is_ci_1.isCI(),
  4829. authorization: api_token_1.getAuthHeader(),
  4830. },
  4831. body: {
  4832. scanResult,
  4833. },
  4834. qs: common_1.assembleQueryString(options),
  4835. });
  4836. }
  4837. return payloads;
  4838. }
  4839. catch (error) {
  4840. if (ecosystem === 'docker' && error.message === 'authentication required') {
  4841. throw new errors_1.DockerImageNotFoundError(options.path);
  4842. }
  4843. if (ecosystem === 'docker' && error.message === 'invalid image format') {
  4844. throw new errors_1.DockerImageNotFoundError(options.path);
  4845. }
  4846. throw error;
  4847. }
  4848. finally {
  4849. spinner_1.spinner.clear(spinnerLbl)();
  4850. }
  4851. }
  4852. exports.assembleEcosystemPayloads = assembleEcosystemPayloads;
  4853. /***/ }),
  4854. /***/ 34013:
  4855. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4856. "use strict";
  4857. Object.defineProperty(exports, "__esModule", ({ value: true }));
  4858. exports.convertTestDepGraphResultToLegacy = exports.SEVERITY = void 0;
  4859. const values = __webpack_require__(17720);
  4860. const common_1 = __webpack_require__(53110);
  4861. var SEVERITY;
  4862. (function (SEVERITY) {
  4863. SEVERITY["LOW"] = "low";
  4864. SEVERITY["MEDIUM"] = "medium";
  4865. SEVERITY["HIGH"] = "high";
  4866. SEVERITY["CRITICAL"] = "critical";
  4867. })(SEVERITY = exports.SEVERITY || (exports.SEVERITY = {}));
  4868. function convertTestDepGraphResultToLegacy(res, depGraph, packageManager, options) {
  4869. const result = res.result;
  4870. const upgradePathsMap = new Map();
  4871. for (const pkgInfo of values(result.affectedPkgs)) {
  4872. for (const pkgIssue of values(pkgInfo.issues)) {
  4873. if (pkgIssue.fixInfo && pkgIssue.fixInfo.upgradePaths) {
  4874. for (const upgradePath of pkgIssue.fixInfo.upgradePaths) {
  4875. const legacyFromPath = pkgPathToLegacyPath(upgradePath.path);
  4876. const vulnPathString = getVulnPathString(pkgIssue.issueId, legacyFromPath);
  4877. upgradePathsMap[vulnPathString] = toLegacyUpgradePath(upgradePath.path);
  4878. }
  4879. }
  4880. }
  4881. }
  4882. // generate the legacy vulns array (vuln-data + metada per vulnerable path).
  4883. // use the upgradePathsMap to find available upgrade-paths
  4884. const vulns = [];
  4885. for (const pkgInfo of values(result.affectedPkgs)) {
  4886. for (const vulnPkgPath of depGraph.pkgPathsToRoot(pkgInfo.pkg)) {
  4887. const legacyFromPath = pkgPathToLegacyPath(vulnPkgPath.reverse());
  4888. for (const pkgIssue of values(pkgInfo.issues)) {
  4889. const vulnPathString = getVulnPathString(pkgIssue.issueId, legacyFromPath);
  4890. const upgradePath = upgradePathsMap[vulnPathString] || [];
  4891. // TODO: we need the full issue-data for every path only for the --json output,
  4892. // consider picking only the required fields,
  4893. // and append the full data only for --json, to minimize chance of out-of-memory
  4894. const annotatedIssue = Object.assign({}, result.issuesData[pkgIssue.issueId], {
  4895. from: legacyFromPath,
  4896. upgradePath,
  4897. isUpgradable: !!upgradePath[0] || !!upgradePath[1],
  4898. isPatchable: pkgIssue.fixInfo.isPatchable,
  4899. name: pkgInfo.pkg.name,
  4900. version: pkgInfo.pkg.version,
  4901. nearestFixedInVersion: pkgIssue.fixInfo.nearestFixedInVersion,
  4902. }); // TODO(kyegupov): get rid of type assertion
  4903. vulns.push(annotatedIssue);
  4904. }
  4905. }
  4906. }
  4907. const dockerRes = result.docker;
  4908. if (dockerRes && dockerRes.binariesVulns) {
  4909. const binariesVulns = dockerRes.binariesVulns;
  4910. for (const pkgInfo of values(binariesVulns.affectedPkgs)) {
  4911. for (const pkgIssue of values(pkgInfo.issues)) {
  4912. const pkgAndVersion = (pkgInfo.pkg.name +
  4913. '@' +
  4914. pkgInfo.pkg.version);
  4915. const annotatedIssue = Object.assign({}, binariesVulns.issuesData[pkgIssue.issueId], {
  4916. from: ['Upstream', pkgAndVersion],
  4917. upgradePath: [],
  4918. isUpgradable: false,
  4919. isPatchable: false,
  4920. name: pkgInfo.pkg.name,
  4921. version: pkgInfo.pkg.version,
  4922. nearestFixedInVersion: pkgIssue.fixInfo.nearestFixedInVersion,
  4923. }); // TODO(kyegupov): get rid of forced type assertion
  4924. vulns.push(annotatedIssue);
  4925. }
  4926. }
  4927. }
  4928. const meta = res.meta || {};
  4929. const severityThreshold = options.severityThreshold === SEVERITY.LOW
  4930. ? undefined
  4931. : options.severityThreshold;
  4932. const legacyRes = {
  4933. vulnerabilities: vulns,
  4934. ok: vulns.length === 0,
  4935. dependencyCount: depGraph.getPkgs().length - 1,
  4936. org: meta.org,
  4937. policy: meta.policy,
  4938. isPrivate: !meta.isPublic,
  4939. licensesPolicy: meta.licensesPolicy || null,
  4940. packageManager,
  4941. projectId: meta.projectId,
  4942. ignoreSettings: meta.ignoreSettings || null,
  4943. docker: result.docker,
  4944. summary: getSummary(vulns, severityThreshold),
  4945. severityThreshold,
  4946. remediation: result.remediation,
  4947. };
  4948. return legacyRes;
  4949. }
  4950. exports.convertTestDepGraphResultToLegacy = convertTestDepGraphResultToLegacy;
  4951. function getVulnPathString(issueId, vulnPath) {
  4952. return issueId + '|' + JSON.stringify(vulnPath);
  4953. }
  4954. function pkgPathToLegacyPath(pkgPath) {
  4955. return pkgPath.map(toLegacyPkgId);
  4956. }
  4957. function toLegacyUpgradePath(upgradePath) {
  4958. return upgradePath
  4959. .filter((item) => !item.isDropped)
  4960. .map((item) => {
  4961. if (!item.newVersion) {
  4962. return false;
  4963. }
  4964. return `${item.name}@${item.newVersion}`;
  4965. });
  4966. }
  4967. function toLegacyPkgId(pkg) {
  4968. return `${pkg.name}@${pkg.version || '*'}`;
  4969. }
  4970. function getSummary(vulns, severityThreshold) {
  4971. const count = vulns.length;
  4972. let countText = '' + count;
  4973. const severityFilters = [];
  4974. const severitiesArray = common_1.SEVERITIES.map((s) => s.verboseName);
  4975. if (severityThreshold) {
  4976. severitiesArray
  4977. .slice(severitiesArray.indexOf(severityThreshold))
  4978. .forEach((sev) => {
  4979. severityFilters.push(sev);
  4980. });
  4981. }
  4982. if (!count) {
  4983. if (severityFilters.length) {
  4984. return `No ${severityFilters.join(' or ')} severity vulnerabilities`;
  4985. }
  4986. return 'No known vulnerabilities';
  4987. }
  4988. if (severityFilters.length) {
  4989. countText += ' ' + severityFilters.join(' or ') + ' severity';
  4990. }
  4991. return `${countText} vulnerable dependency ${pl('path', count)}`;
  4992. }
  4993. function pl(word, count) {
  4994. const ext = {
  4995. y: 'ies',
  4996. default: 's',
  4997. };
  4998. const last = word.split('').pop();
  4999. if (count > 1) {
  5000. return word.slice(0, -1) + (ext[last] || last + ext.default);
  5001. }
  5002. return word;
  5003. }
  5004. /***/ }),
  5005. /***/ 7964:
  5006. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5007. "use strict";
  5008. Object.defineProperty(exports, "__esModule", ({ value: true }));
  5009. exports.runTest = void 0;
  5010. const fs = __webpack_require__(35747);
  5011. const get = __webpack_require__(29208);
  5012. const path = __webpack_require__(85622);
  5013. const pathUtil = __webpack_require__(85622);
  5014. const debugModule = __webpack_require__(15158);
  5015. const chalk_1 = __webpack_require__(32589);
  5016. const theme_1 = __webpack_require__(86988);
  5017. const snyk_module_1 = __webpack_require__(60390);
  5018. const depGraphLib = __webpack_require__(71479);
  5019. const theme = __webpack_require__(86988);
  5020. const legacy_1 = __webpack_require__(34013);
  5021. const errors_1 = __webpack_require__(55191);
  5022. const snyk = __webpack_require__(9146);
  5023. const is_ci_1 = __webpack_require__(10090);
  5024. const common = __webpack_require__(53110);
  5025. const config_1 = __webpack_require__(25425);
  5026. const analytics = __webpack_require__(82744);
  5027. const print_deps_1 = __webpack_require__(79792);
  5028. const projectMetadata = __webpack_require__(3594);
  5029. const prune_1 = __webpack_require__(87725);
  5030. const get_deps_from_plugin_1 = __webpack_require__(4842);
  5031. const extract_package_manager_1 = __webpack_require__(22805);
  5032. const get_extra_project_count_1 = __webpack_require__(34355);
  5033. const policy_1 = __webpack_require__(32615);
  5034. const api_token_1 = __webpack_require__(95181);
  5035. const ecosystems_1 = __webpack_require__(5168);
  5036. const assemble_payloads_1 = __webpack_require__(38080);
  5037. const request_1 = __webpack_require__(52050);
  5038. const spinner_1 = __webpack_require__(86766);
  5039. const debug = debugModule('snyk:run-test');
  5040. function prepareResponseForParsing(payload, response, options) {
  5041. const ecosystem = ecosystems_1.getEcosystem(options);
  5042. return ecosystem
  5043. ? prepareEcosystemResponseForParsing(payload, response, options)
  5044. : prepareLanguagesResponseForParsing(payload);
  5045. }
  5046. function prepareEcosystemResponseForParsing(payload, response, options) {
  5047. var _a, _b, _c, _d, _e, _f;
  5048. const testDependenciesRequest = payload.body;
  5049. const payloadBody = testDependenciesRequest === null || testDependenciesRequest === void 0 ? void 0 : testDependenciesRequest.scanResult;
  5050. const depGraphData = (_a = response === null || response === void 0 ? void 0 : response.result) === null || _a === void 0 ? void 0 : _a.depGraphData;
  5051. const depGraph = depGraphData !== undefined
  5052. ? depGraphLib.createFromJSON(depGraphData)
  5053. : undefined;
  5054. const imageUserInstructions = payloadBody === null || payloadBody === void 0 ? void 0 : payloadBody.facts.find((fact) => fact.type === 'dockerfileAnalysis' ||
  5055. fact.type === 'autoDetectedUserInstructions');
  5056. const dockerfilePackages = (_b = imageUserInstructions === null || imageUserInstructions === void 0 ? void 0 : imageUserInstructions.data) === null || _b === void 0 ? void 0 : _b.dockerfilePackages;
  5057. const projectName = (payloadBody === null || payloadBody === void 0 ? void 0 : payloadBody.name) || (depGraph === null || depGraph === void 0 ? void 0 : depGraph.rootPkg.name);
  5058. const packageManager = (_c = payloadBody === null || payloadBody === void 0 ? void 0 : payloadBody.identity) === null || _c === void 0 ? void 0 : _c.type;
  5059. const targetFile = ((_d = payloadBody === null || payloadBody === void 0 ? void 0 : payloadBody.identity) === null || _d === void 0 ? void 0 : _d.targetFile) || options.file;
  5060. const platform = (_f = (_e = payloadBody === null || payloadBody === void 0 ? void 0 : payloadBody.identity) === null || _e === void 0 ? void 0 : _e.args) === null || _f === void 0 ? void 0 : _f.platform;
  5061. analytics.add('depGraph', !!depGraph);
  5062. analytics.add('isDocker', !!options.docker);
  5063. return {
  5064. depGraph,
  5065. dockerfilePackages,
  5066. projectName,
  5067. targetFile,
  5068. pkgManager: packageManager,
  5069. displayTargetFile: targetFile,
  5070. foundProjectCount: undefined,
  5071. payloadPolicy: payloadBody === null || payloadBody === void 0 ? void 0 : payloadBody.policy,
  5072. platform,
  5073. scanResult: payloadBody,
  5074. };
  5075. }
  5076. function prepareLanguagesResponseForParsing(payload) {
  5077. const payloadBody = payload.body;
  5078. const payloadPolicy = payloadBody && payloadBody.policy;
  5079. const depGraph = payloadBody && payloadBody.depGraph;
  5080. const pkgManager = depGraph &&
  5081. depGraph.pkgManager &&
  5082. depGraph.pkgManager.name;
  5083. const targetFile = payloadBody && payloadBody.targetFile;
  5084. const projectName = (payloadBody === null || payloadBody === void 0 ? void 0 : payloadBody.projectNameOverride) || (payloadBody === null || payloadBody === void 0 ? void 0 : payloadBody.originalProjectName);
  5085. const foundProjectCount = payloadBody === null || payloadBody === void 0 ? void 0 : payloadBody.foundProjectCount;
  5086. const displayTargetFile = payloadBody === null || payloadBody === void 0 ? void 0 : payloadBody.displayTargetFile;
  5087. let dockerfilePackages;
  5088. if (payloadBody &&
  5089. payloadBody.docker &&
  5090. payloadBody.docker.dockerfilePackages) {
  5091. dockerfilePackages = payloadBody.docker.dockerfilePackages;
  5092. }
  5093. analytics.add('depGraph', !!depGraph);
  5094. analytics.add('isDocker', !!(payloadBody && payloadBody.docker));
  5095. return {
  5096. depGraph,
  5097. payloadPolicy,
  5098. pkgManager,
  5099. targetFile,
  5100. projectName,
  5101. foundProjectCount,
  5102. displayTargetFile,
  5103. dockerfilePackages,
  5104. };
  5105. }
  5106. function isTestDependenciesResponse(response) {
  5107. var _a;
  5108. const assumedTestDependenciesResponse = response;
  5109. return ((_a = assumedTestDependenciesResponse === null || assumedTestDependenciesResponse === void 0 ? void 0 : assumedTestDependenciesResponse.result) === null || _a === void 0 ? void 0 : _a.issues) !== undefined;
  5110. }
  5111. function convertIssuesToAffectedPkgs(response) {
  5112. if (!response.result) {
  5113. return response;
  5114. }
  5115. if (!isTestDependenciesResponse(response)) {
  5116. return response;
  5117. }
  5118. response.result['affectedPkgs'] = getAffectedPkgsFromIssues(response.result.issues);
  5119. return response;
  5120. }
  5121. function getAffectedPkgsFromIssues(issues) {
  5122. const result = {};
  5123. for (const issue of issues) {
  5124. const packageId = `${issue.pkgName}@${issue.pkgVersion || ''}`;
  5125. if (result[packageId] === undefined) {
  5126. result[packageId] = {
  5127. pkg: { name: issue.pkgName, version: issue.pkgVersion },
  5128. issues: {},
  5129. };
  5130. }
  5131. result[packageId].issues[issue.issueId] = issue;
  5132. }
  5133. return result;
  5134. }
  5135. async function sendAndParseResults(payloads, spinnerLbl, root, options) {
  5136. const results = [];
  5137. for (const payload of payloads) {
  5138. await spinner_1.spinner.clear(spinnerLbl)();
  5139. if (!options.quiet) {
  5140. await spinner_1.spinner(spinnerLbl);
  5141. }
  5142. /** sendTestPayload() deletes the request.body from the payload once completed. */
  5143. const payloadCopy = Object.assign({}, payload);
  5144. const res = await sendTestPayload(payload);
  5145. const { depGraph, payloadPolicy, pkgManager, targetFile, projectName, foundProjectCount, displayTargetFile, dockerfilePackages, platform, scanResult, } = prepareResponseForParsing(payloadCopy, res, options);
  5146. const ecosystem = ecosystems_1.getEcosystem(options);
  5147. if (ecosystem && options['print-deps']) {
  5148. await spinner_1.spinner.clear(spinnerLbl)();
  5149. await print_deps_1.maybePrintDepGraph(options, depGraph);
  5150. }
  5151. const legacyRes = convertIssuesToAffectedPkgs(res);
  5152. const result = await parseRes(depGraph, pkgManager, legacyRes, options, payload, payloadPolicy, root, dockerfilePackages);
  5153. results.push({
  5154. ...result,
  5155. targetFile,
  5156. projectName,
  5157. foundProjectCount,
  5158. displayTargetFile,
  5159. platform,
  5160. scanResult,
  5161. });
  5162. }
  5163. return results;
  5164. }
  5165. async function runTest(projectType, root, options) {
  5166. const spinnerLbl = 'Querying vulnerabilities database...';
  5167. try {
  5168. const payloads = await assemblePayloads(root, options);
  5169. return await sendAndParseResults(payloads, spinnerLbl, root, options);
  5170. }
  5171. catch (error) {
  5172. debug('Error running test', { error });
  5173. // handling denial from registry because of the feature flag
  5174. // currently done for go.mod
  5175. const isFeatureNotAllowed = error.code === 403 && error.message.includes('Feature not allowed');
  5176. const hasFailedToGetVulnerabilities = error.code === 404 &&
  5177. error.name.includes('FailedToGetVulnerabilitiesError') &&
  5178. !error.userMessage;
  5179. if (isFeatureNotAllowed) {
  5180. throw errors_1.NoSupportedManifestsFoundError([root]);
  5181. }
  5182. if (hasFailedToGetVulnerabilities) {
  5183. throw errors_1.FailedToGetVulnsFromUnavailableResource(root, error.code);
  5184. }
  5185. if (ecosystems_1.getEcosystem(options) === 'docker' &&
  5186. error.statusCode === 401 &&
  5187. [
  5188. 'authentication required',
  5189. '{"details":"incorrect username or password"}\n',
  5190. ].includes(error.message)) {
  5191. throw new errors_1.DockerImageNotFoundError(root);
  5192. }
  5193. throw new errors_1.FailedToRunTestError(error.userMessage ||
  5194. error.message ||
  5195. `Failed to test ${projectType} project`, error.code);
  5196. }
  5197. finally {
  5198. spinner_1.spinner.clear(spinnerLbl)();
  5199. }
  5200. }
  5201. exports.runTest = runTest;
  5202. async function parseRes(depGraph, pkgManager, res, options, payload, payloadPolicy, root, dockerfilePackages) {
  5203. var _a;
  5204. // TODO: docker doesn't have a package manager
  5205. // so this flow will not be applicable
  5206. // refactor to separate
  5207. if (depGraph && pkgManager) {
  5208. res = legacy_1.convertTestDepGraphResultToLegacy(res, // Double "as" required by Typescript for dodgy assertions
  5209. depGraph, pkgManager, options);
  5210. // For Node.js: inject additional information (for remediation etc.) into the response.
  5211. if (payload.modules) {
  5212. res.dependencyCount =
  5213. payload.modules.numDependencies || depGraph.getPkgs().length - 1;
  5214. if (res.vulnerabilities) {
  5215. res.vulnerabilities.forEach((vuln) => {
  5216. if (payload.modules && payload.modules.pluck) {
  5217. const plucked = payload.modules.pluck(vuln.from, vuln.name, vuln.version);
  5218. vuln.__filename = plucked.__filename;
  5219. vuln.shrinkwrap = plucked.shrinkwrap;
  5220. vuln.bundled = plucked.bundled;
  5221. // this is an edgecase when we're testing the directly vuln pkg
  5222. if (vuln.from.length === 1) {
  5223. return;
  5224. }
  5225. const parentPkg = snyk_module_1.parsePackageString(vuln.from[1]);
  5226. const parent = payload.modules.pluck(vuln.from.slice(0, 2), parentPkg.name, parentPkg.version);
  5227. vuln.parentDepType = parent.depType;
  5228. }
  5229. });
  5230. }
  5231. }
  5232. }
  5233. // TODO: is this needed? we filter on the other side already based on policy
  5234. // this will move to be filtered server side soon & it will support `'ignore-policy'`
  5235. analytics.add('vulns-pre-policy', res.vulnerabilities.length);
  5236. res.filesystemPolicy = !!payloadPolicy;
  5237. if (!options['ignore-policy']) {
  5238. res.policy = res.policy || payloadPolicy;
  5239. const policy = await snyk.policy.loadFromText(res.policy);
  5240. res = policy.filter(res, root);
  5241. }
  5242. analytics.add('vulns', res.vulnerabilities.length);
  5243. if (res.docker && dockerfilePackages) {
  5244. res.vulnerabilities = res.vulnerabilities.map((vuln) => {
  5245. const dockerfilePackage = dockerfilePackages[vuln.name.split('/')[0]];
  5246. if (dockerfilePackage) {
  5247. vuln.dockerfileInstruction =
  5248. dockerfilePackage.installCommand;
  5249. }
  5250. vuln.dockerBaseImage = res.docker.baseImage;
  5251. return vuln;
  5252. });
  5253. }
  5254. if (options.docker && ((_a = res.docker) === null || _a === void 0 ? void 0 : _a.baseImage) &&
  5255. options['exclude-base-image-vulns']) {
  5256. const filteredVulns = res.vulnerabilities.filter((vuln) => vuln.dockerfileInstruction);
  5257. // `exclude-base-image-vulns` might have left us with no vulns, so `ok` is now `true`
  5258. if (res.vulnerabilities.length !== 0 &&
  5259. filteredVulns.length === 0 &&
  5260. !res.ok) {
  5261. res.ok = true;
  5262. }
  5263. res.vulnerabilities = filteredVulns;
  5264. }
  5265. res.uniqueCount = countUniqueVulns(res.vulnerabilities);
  5266. return res;
  5267. }
  5268. function sendTestPayload(payload) {
  5269. var _a;
  5270. const payloadBody = payload.body;
  5271. const filesystemPolicy = payload.body && !!((payloadBody === null || payloadBody === void 0 ? void 0 : payloadBody.policy) || ((_a = payloadBody === null || payloadBody === void 0 ? void 0 : payloadBody.scanResult) === null || _a === void 0 ? void 0 : _a.policy));
  5272. return new Promise((resolve, reject) => {
  5273. request_1.makeRequest(payload, (error, res, body) => {
  5274. if (error) {
  5275. return reject(error);
  5276. }
  5277. if (res.statusCode !== 200) {
  5278. const err = handleTestHttpErrorResponse(res, body);
  5279. return reject(err);
  5280. }
  5281. body.filesystemPolicy = filesystemPolicy;
  5282. resolve(body);
  5283. });
  5284. });
  5285. }
  5286. function handleTestHttpErrorResponse(res, body) {
  5287. const { statusCode } = res;
  5288. let err;
  5289. const userMessage = body && body.userMessage;
  5290. switch (statusCode) {
  5291. case 401:
  5292. case 403:
  5293. err = errors_1.AuthFailedError(userMessage, statusCode);
  5294. err.innerError = body.stack;
  5295. break;
  5296. case 404:
  5297. err = new errors_1.NotFoundError(userMessage);
  5298. err.innerError = body.stack;
  5299. break;
  5300. case 500:
  5301. err = new errors_1.InternalServerError(userMessage);
  5302. err.innerError = body.stack;
  5303. break;
  5304. default:
  5305. err = new errors_1.FailedToGetVulnerabilitiesError(userMessage, statusCode);
  5306. err.innerError = body.error;
  5307. }
  5308. return err;
  5309. }
  5310. function assemblePayloads(root, options) {
  5311. let isLocal;
  5312. if (options.docker) {
  5313. isLocal = true;
  5314. }
  5315. else {
  5316. // TODO: Refactor this check so we don't require files when tests are using mocks
  5317. isLocal = fs.existsSync(root);
  5318. }
  5319. analytics.add('local', isLocal);
  5320. const ecosystem = ecosystems_1.getEcosystem(options);
  5321. if (ecosystem) {
  5322. return assemble_payloads_1.assembleEcosystemPayloads(ecosystem, options);
  5323. }
  5324. if (isLocal) {
  5325. return assembleLocalPayloads(root, options);
  5326. }
  5327. return assembleRemotePayloads(root, options);
  5328. }
  5329. // Payload to send to the Registry for scanning a package from the local filesystem.
  5330. async function assembleLocalPayloads(root, options) {
  5331. // For --all-projects packageManager is yet undefined here. Use 'all'
  5332. let analysisTypeText = 'all dependencies for ';
  5333. if (options.docker) {
  5334. analysisTypeText = 'docker dependencies for ';
  5335. }
  5336. else if (options.packageManager) {
  5337. analysisTypeText = options.packageManager + ' dependencies for ';
  5338. }
  5339. const spinnerLbl = 'Analyzing ' +
  5340. analysisTypeText +
  5341. (path.relative('.', path.join(root, options.file || '')) ||
  5342. path.relative('..', '.') + ' project dir');
  5343. try {
  5344. const payloads = [];
  5345. await spinner_1.spinner.clear(spinnerLbl)();
  5346. if (!options.quiet) {
  5347. await spinner_1.spinner(spinnerLbl);
  5348. }
  5349. const deps = await get_deps_from_plugin_1.getDepsFromPlugin(root, options);
  5350. const failedResults = deps.failedResults;
  5351. if (failedResults === null || failedResults === void 0 ? void 0 : failedResults.length) {
  5352. await spinner_1.spinner.clear(spinnerLbl)();
  5353. if (!options.json && !options.quiet) {
  5354. console.warn(chalk_1.default.bold.red(`${theme_1.icon.ISSUE} ${failedResults.length}/${failedResults.length +
  5355. deps.scannedProjects
  5356. .length} potential projects failed to get dependencies.`));
  5357. failedResults.forEach((f) => {
  5358. if (f.targetFile) {
  5359. console.warn(theme.color.status.error(`${f.targetFile}:`));
  5360. }
  5361. console.warn(theme.color.status.error(` ${f.errMessage}`));
  5362. });
  5363. }
  5364. debug('getDepsFromPlugin returned failed results, cannot run test/monitor', failedResults);
  5365. if (options['fail-fast']) {
  5366. throw new errors_1.FailedToRunTestError(errors_1.errorMessageWithRetry('Your test request could not be completed.'));
  5367. }
  5368. }
  5369. analytics.add('pluginName', deps.plugin.name);
  5370. const javaVersion = get(deps.plugin, 'meta.versionBuildInfo.metaBuildVersion.javaVersion', null);
  5371. const mvnVersion = get(deps.plugin, 'meta.versionBuildInfo.metaBuildVersion.mvnVersion', null);
  5372. const sbtVersion = get(deps.plugin, 'meta.versionBuildInfo.metaBuildVersion.sbtVersion', null);
  5373. if (javaVersion) {
  5374. analytics.add('javaVersion', javaVersion);
  5375. }
  5376. if (mvnVersion) {
  5377. analytics.add('mvnVersion', mvnVersion);
  5378. }
  5379. if (sbtVersion) {
  5380. analytics.add('sbtVersion', sbtVersion);
  5381. }
  5382. for (const scannedProject of deps.scannedProjects) {
  5383. if (!scannedProject.depTree && !scannedProject.depGraph) {
  5384. debug('scannedProject is missing depGraph or depTree, cannot run test/monitor');
  5385. throw new errors_1.FailedToRunTestError(errors_1.errorMessageWithRetry('Your test request could not be completed.'));
  5386. }
  5387. // prefer dep-graph fallback on dep tree
  5388. // TODO: clean up once dep-graphs only
  5389. const pkg = scannedProject.depGraph
  5390. ? scannedProject.depGraph
  5391. : scannedProject.depTree;
  5392. if (options['print-deps']) {
  5393. if (scannedProject.depGraph) {
  5394. await spinner_1.spinner.clear(spinnerLbl)();
  5395. print_deps_1.maybePrintDepGraph(options, pkg);
  5396. }
  5397. else {
  5398. await spinner_1.spinner.clear(spinnerLbl)();
  5399. print_deps_1.maybePrintDepTree(options, pkg);
  5400. }
  5401. }
  5402. const project = scannedProject;
  5403. const packageManager = extract_package_manager_1.extractPackageManager(project, deps, options);
  5404. if (pkg.docker) {
  5405. const baseImageFromDockerfile = pkg.docker.baseImage;
  5406. if (!baseImageFromDockerfile && options['base-image']) {
  5407. pkg.docker.baseImage = options['base-image'];
  5408. }
  5409. if (baseImageFromDockerfile && deps.plugin && deps.plugin.imageLayers) {
  5410. analytics.add('BaseImage', baseImageFromDockerfile);
  5411. analytics.add('imageLayers', deps.plugin.imageLayers);
  5412. }
  5413. }
  5414. // todo: normalize what target file gets used across plugins and functions
  5415. const targetFile = scannedProject.targetFile || deps.plugin.targetFile || options.file;
  5416. // Forcing options.path to be a string as pathUtil requires is to be stringified
  5417. const targetFileRelativePath = targetFile
  5418. ? pathUtil.resolve(pathUtil.resolve(`${options.path || root}`), targetFile)
  5419. : '';
  5420. let targetFileDir;
  5421. if (targetFileRelativePath) {
  5422. const { dir } = path.parse(targetFileRelativePath);
  5423. targetFileDir = dir;
  5424. }
  5425. const policy = await policy_1.findAndLoadPolicy(root, options.docker ? 'docker' : packageManager, options,
  5426. // TODO: fix this and send only send when we used resolve-deps for node
  5427. // it should be a ExpandedPkgTree type instead
  5428. pkg, targetFileDir);
  5429. analytics.add('packageManager', packageManager);
  5430. if (scannedProject.depGraph) {
  5431. const depGraph = pkg;
  5432. addPackageAnalytics(depGraph.rootPkg.name, depGraph.rootPkg.version);
  5433. }
  5434. if (scannedProject.depTree) {
  5435. const depTree = pkg;
  5436. addPackageAnalytics(depTree.name, depTree.version);
  5437. }
  5438. let target;
  5439. if (scannedProject.depGraph) {
  5440. target = await projectMetadata.getInfo(scannedProject, options);
  5441. }
  5442. else {
  5443. target = await projectMetadata.getInfo(scannedProject, options, pkg);
  5444. }
  5445. const originalProjectName = scannedProject.depGraph
  5446. ? pkg.rootPkg.name
  5447. : pkg.name;
  5448. const body = {
  5449. // WARNING: be careful changing this as it affects project uniqueness
  5450. targetFile: project.plugin.targetFile,
  5451. // TODO: Remove relativePath prop once we gather enough ruby related logs
  5452. targetFileRelativePath: `${targetFileRelativePath}`,
  5453. targetReference: options['target-reference'],
  5454. projectNameOverride: options.projectName,
  5455. originalProjectName,
  5456. policy: policy ? policy.toString() : undefined,
  5457. foundProjectCount: await get_extra_project_count_1.getExtraProjectCount(root, options, deps),
  5458. displayTargetFile: targetFile,
  5459. docker: pkg.docker,
  5460. hasDevDependencies: pkg.hasDevDependencies,
  5461. target,
  5462. };
  5463. let depGraph;
  5464. if (scannedProject.depGraph) {
  5465. depGraph = scannedProject.depGraph;
  5466. }
  5467. else {
  5468. // Graphs are more compact and robust representations.
  5469. // Legacy parts of the code are still using trees, but will eventually be fully migrated.
  5470. debug('converting dep-tree to dep-graph', {
  5471. name: pkg.name,
  5472. targetFile: scannedProject.targetFile || options.file,
  5473. });
  5474. depGraph = await depGraphLib.legacy.depTreeToGraph(pkg, packageManager);
  5475. debug('done converting dep-tree to dep-graph', {
  5476. uniquePkgsCount: depGraph.getPkgs().length,
  5477. });
  5478. }
  5479. const pruneIsRequired = options.pruneRepeatedSubdependencies;
  5480. if (packageManager) {
  5481. depGraph = await prune_1.pruneGraph(depGraph, packageManager, pruneIsRequired);
  5482. }
  5483. body.depGraph = depGraph;
  5484. const reqUrl = config_1.default.API +
  5485. (options.testDepGraphDockerEndpoint ||
  5486. options.vulnEndpoint ||
  5487. '/test-dep-graph');
  5488. const payload = {
  5489. method: 'POST',
  5490. url: reqUrl,
  5491. json: true,
  5492. headers: {
  5493. 'x-is-ci': is_ci_1.isCI(),
  5494. authorization: api_token_1.getAuthHeader(),
  5495. },
  5496. qs: common.assembleQueryString(options),
  5497. body,
  5498. };
  5499. if (packageManager && ['yarn', 'npm'].indexOf(packageManager) !== -1) {
  5500. const isLockFileBased = targetFile &&
  5501. (targetFile.endsWith('package-lock.json') ||
  5502. targetFile.endsWith('yarn.lock'));
  5503. if (!isLockFileBased || options.traverseNodeModules) {
  5504. payload.modules = pkg; // See the output of resolve-deps
  5505. }
  5506. }
  5507. payloads.push(payload);
  5508. }
  5509. return payloads;
  5510. }
  5511. finally {
  5512. await spinner_1.spinner.clear(spinnerLbl)();
  5513. }
  5514. }
  5515. // Payload to send to the Registry for scanning a remote package.
  5516. async function assembleRemotePayloads(root, options) {
  5517. const pkg = snyk_module_1.parsePackageString(root);
  5518. debug('testing remote: %s', pkg.name + '@' + pkg.version);
  5519. addPackageAnalytics(pkg.name, pkg.version);
  5520. const encodedName = encodeURIComponent(pkg.name + '@' + pkg.version);
  5521. // options.vulnEndpoint is only used by `snyk protect` (i.e. local filesystem tests)
  5522. const url = `${config_1.default.API}${options.vulnEndpoint ||
  5523. `/vuln/${options.packageManager}`}/${encodedName}`;
  5524. return [
  5525. {
  5526. method: 'GET',
  5527. url,
  5528. qs: common.assembleQueryString(options),
  5529. json: true,
  5530. headers: {
  5531. 'x-is-ci': is_ci_1.isCI(),
  5532. authorization: api_token_1.getAuthHeader(),
  5533. },
  5534. },
  5535. ];
  5536. }
  5537. function addPackageAnalytics(name, version) {
  5538. analytics.add('packageName', name);
  5539. analytics.add('packageVersion', version);
  5540. analytics.add('package', name + '@' + version);
  5541. }
  5542. function countUniqueVulns(vulns) {
  5543. const seen = {};
  5544. for (const curr of vulns) {
  5545. seen[curr.id] = true;
  5546. }
  5547. return Object.keys(seen).length;
  5548. }
  5549. /***/ }),
  5550. /***/ 66487:
  5551. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5552. "use strict";
  5553. Object.defineProperty(exports, "__esModule", ({ value: true }));
  5554. exports.execute = void 0;
  5555. const childProcess = __webpack_require__(63129);
  5556. function execute(command, args, options) {
  5557. const spawnOptions = { shell: true };
  5558. if (options && options.cwd) {
  5559. spawnOptions.cwd = options.cwd;
  5560. }
  5561. return new Promise((resolve, reject) => {
  5562. let stdout = '';
  5563. let stderr = '';
  5564. const proc = childProcess.spawn(command, args, spawnOptions);
  5565. if (proc.stdout) {
  5566. proc.stdout.on('data', (data) => {
  5567. stdout += data;
  5568. });
  5569. }
  5570. if (proc.stderr) {
  5571. proc.stderr.on('data', (data) => {
  5572. stderr += data;
  5573. });
  5574. }
  5575. proc.on('close', (code) => {
  5576. if (code !== 0) {
  5577. return reject(stdout || stderr);
  5578. }
  5579. resolve(stdout || stderr);
  5580. });
  5581. });
  5582. }
  5583. exports.execute = execute;
  5584. /***/ }),
  5585. /***/ 9146:
  5586. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  5587. const snykConfig = __webpack_require__(25425);
  5588. // This module is kind of "world object" that is used to indirectly import modules.
  5589. // This also introduces some circular imports.
  5590. // TODO(kyegupov): untangle this, resolve circular imports, convert to Typescript
  5591. const snyk = {};
  5592. module.exports = snyk;
  5593. snyk.id = snykConfig.id;
  5594. const apiToken = __webpack_require__(95181);
  5595. // make snyk.api *always* get the latest api token from the config store
  5596. Object.defineProperty(snyk, 'api', {
  5597. enumerable: true,
  5598. configurable: true,
  5599. get: function() {
  5600. return apiToken.api();
  5601. },
  5602. set: function(value) {
  5603. snykConfig.api = value;
  5604. },
  5605. });
  5606. snyk.test = __webpack_require__(53378);
  5607. snyk.policy = __webpack_require__(70535);
  5608. // this is the user config, and not the internal config
  5609. snyk.config = __webpack_require__(28137).config;
  5610. /***/ }),
  5611. /***/ 97467:
  5612. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  5613. const gemfile = __webpack_require__(10635);
  5614. module.exports = gemfileLockToDependencies;
  5615. const detectCycles = (dep, chain) => {
  5616. if (chain.indexOf(dep) >= 0) {
  5617. const error = Error('Cyclic dependency detected in lockfile');
  5618. const UNPROCESSABLE_ENTITY = 422;
  5619. error.code = UNPROCESSABLE_ENTITY;
  5620. error.meta = { dep, chain };
  5621. throw error;
  5622. }
  5623. };
  5624. const gemfileReducer = (lockFile, allDeps, ancestors) => (deps, dep) => {
  5625. const gemspec = lockFile.specs[dep];
  5626. // If for some reason a dependency isn't included in the specs then its
  5627. // better to just ignore it (otherwise all processing fails).
  5628. // This happens for bundler itself, it isn't included in the Gemfile.lock
  5629. // specs, even if its a dependency! (and that isn't documented anywhere)
  5630. if (gemspec) {
  5631. detectCycles(dep, ancestors);
  5632. if (allDeps.has(dep)) {
  5633. deps[dep] = allDeps.get(dep);
  5634. } else {
  5635. deps[dep] = {
  5636. name: dep,
  5637. version: gemspec.version,
  5638. };
  5639. allDeps.set(dep, deps[dep]);
  5640. deps[dep].dependencies = Object.keys(gemspec)
  5641. .filter((k) => k !== 'version')
  5642. .reduce(gemfileReducer(lockFile, allDeps, ancestors.concat([dep])), {});
  5643. }
  5644. }
  5645. return deps;
  5646. };
  5647. function gemfileLockToDependencies(fileContents) {
  5648. const lockFile = gemfile.interpret(fileContents, true);
  5649. return (
  5650. Object.keys(lockFile.dependencies || {})
  5651. // this is required to sanitise git deps with no exact version
  5652. // listed as `rspec!`
  5653. .map((dep) => dep.match(/[^!]+/)[0])
  5654. .reduce(gemfileReducer(lockFile, new Map(), []), {})
  5655. );
  5656. }
  5657. /***/ }),
  5658. /***/ 53378:
  5659. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  5660. module.exports = test;
  5661. const detect = __webpack_require__(45318);
  5662. const { runTest } = __webpack_require__(7964);
  5663. const chalk = __webpack_require__(32589);
  5664. const pm = __webpack_require__(53847);
  5665. const { UnsupportedPackageManagerError } = __webpack_require__(55191);
  5666. const { isMultiProjectScan } = __webpack_require__(62435);
  5667. async function test(root, options, callback) {
  5668. if (typeof options === 'function') {
  5669. callback = options;
  5670. options = {};
  5671. }
  5672. if (!options) {
  5673. options = {};
  5674. }
  5675. const promise = executeTest(root, options);
  5676. if (callback) {
  5677. promise
  5678. .then((res) => {
  5679. callback(null, res);
  5680. })
  5681. .catch(callback);
  5682. }
  5683. return promise;
  5684. }
  5685. async function executeTest(root, options) {
  5686. try {
  5687. if (!options.allProjects) {
  5688. options.packageManager = detect.detectPackageManager(root, options);
  5689. }
  5690. return run(root, options).then((results) => {
  5691. for (const res of results) {
  5692. if (!res.packageManager) {
  5693. res.packageManager = options.packageManager;
  5694. }
  5695. }
  5696. if (results.length === 1) {
  5697. // Return only one result if only one found as this is the default usecase
  5698. return results[0];
  5699. }
  5700. // For gradle, yarnWorkspaces, allProjects we may be returning more than one result
  5701. return results;
  5702. });
  5703. } catch (error) {
  5704. return Promise.reject(
  5705. chalk.red.bold(error.message ? error.message : error),
  5706. );
  5707. }
  5708. }
  5709. function run(root, options) {
  5710. const projectType = options.packageManager;
  5711. validateProjectType(options, projectType);
  5712. return runTest(projectType, root, options);
  5713. }
  5714. function validateProjectType(options, projectType) {
  5715. if (
  5716. !(
  5717. options.docker ||
  5718. isMultiProjectScan(options) ||
  5719. pm.SUPPORTED_PACKAGE_MANAGER_NAME[projectType]
  5720. )
  5721. ) {
  5722. throw new UnsupportedPackageManagerError(projectType);
  5723. }
  5724. }
  5725. /***/ })
  5726. };
  5727. ;
  5728. //# sourceMappingURL=784.index.js.map