[{"data":1,"prerenderedAt":420},["ShallowReactive",2],{"rule-eval-usage":3},{"id":4,"title":5,"body":6,"breadcrumb":384,"coderail":391,"dateModified":410,"datePublished":410,"description":411,"extension":412,"meta":413,"navigation":174,"next":410,"path":414,"prev":410,"schemaType":415,"seo":416,"stem":417,"wide":418,"__hash__":419},"docs\u002Frules\u002Feval-usage.md","eval() usage detected",{"type":7,"value":8,"toc":376},"minimark",[9,16,58,63,81,85,100,104,234,238,282,286,344,348,372],[10,11,12],"p",{},[13,14,15],"strong",{},"Summary",[17,18,19,30,40,46,52],"ul",{},[20,21,22,25,26],"li",{},[13,23,24],{},"rule_id"," — ",[27,28,29],"code",{},"eval-usage",[20,31,32,35,36,39],{},[13,33,34],{},"purpose"," — Detect Custom HTML tags that call ",[27,37,38],{},"eval()"," to execute strings as code",[20,41,42,45],{},[13,43,44],{},"effect"," — XSS vector; disables JavaScript engine optimizations for the affected function",[20,47,48,51],{},[13,49,50],{},"layer"," — container",[20,53,54,57],{},[13,55,56],{},"reversibility"," — non-destructive",[59,60,62],"h2",{"id":61},"what-fires-this","What fires this",[10,64,65,66,69,70,73,74,77,78,80],{},"The rule iterates active Custom HTML tags via ",[27,67,68],{},"getHtmlTags"," and filters for those where ",[27,71,72],{},"codeAnalysis.hasEval"," is true. The parser sets this flag when it detects a ",[27,75,76],{},"eval("," call in the tag code. Every tag with that flag fires the rule. Paused tags are excluded. The rule does not inspect what string is passed to ",[27,79,38],{}," — any call triggers the issue regardless of the source.",[59,82,84],{"id":83},"why-it-matters","Why it matters",[10,86,87,89,90,92,93,95,96,99],{},[27,88,38],{}," executes an arbitrary string as JavaScript in the current scope. If any part of that string is influenced by user input — URL parameters, cookie values, dataLayer contents, or remote API responses — the tag becomes an XSS vector allowing arbitrary script injection. Beyond security, V8 exits optimized compilation mode for any function containing ",[27,91,38],{},", degrading performance across the affected script. There is no GTM use case that requires ",[27,94,38],{},": JSON strings belong in ",[27,97,98],{},"JSON.parse()",", and dynamic logic belongs in explicit conditionals.",[59,101,103],{"id":102},"example","Before \u002F after",[105,106,107,188],"compare",{},[108,109,111],"compare-col",{"label":110},"Before — flagged",[112,113,118],"pre",{"className":114,"code":115,"language":116,"meta":117,"style":117},"language-js shiki shiki-themes github-light github-dark","\u002F\u002F Parsing a JSON string — triggers eval-usage\nvar config = eval('(' + window.myConfig + ')')\n\ndataLayer.push({ config: config })\n","js","",[27,119,120,129,169,176],{"__ignoreMap":117},[121,122,125],"span",{"class":123,"line":124},"line",1,[121,126,128],{"class":127},"sJ8bj","\u002F\u002F Parsing a JSON string — triggers eval-usage\n",[121,130,132,136,140,143,147,150,154,157,160,163,166],{"class":123,"line":131},2,[121,133,135],{"class":134},"szBVR","var",[121,137,139],{"class":138},"sVt8B"," config ",[121,141,142],{"class":134},"=",[121,144,146],{"class":145},"sScJk"," eval",[121,148,149],{"class":138},"(",[121,151,153],{"class":152},"sZZnC","'('",[121,155,156],{"class":134}," +",[121,158,159],{"class":138}," window.myConfig ",[121,161,162],{"class":134},"+",[121,164,165],{"class":152}," ')'",[121,167,168],{"class":138},")\n",[121,170,172],{"class":123,"line":171},3,[121,173,175],{"emptyLinePlaceholder":174},true,"\n",[121,177,179,182,185],{"class":123,"line":178},4,[121,180,181],{"class":138},"dataLayer.",[121,183,184],{"class":145},"push",[121,186,187],{"class":138},"({ config: config })\n",[108,189,191],{"label":190},"After — fixed",[112,192,194],{"className":114,"code":193,"language":116,"meta":117,"style":117},"\u002F\u002F Safe parse — no code execution\nvar config = JSON.parse(window.myConfig)\n\ndataLayer.push({ config: config })\n",[27,195,196,201,222,226],{"__ignoreMap":117},[121,197,198],{"class":123,"line":124},[121,199,200],{"class":127},"\u002F\u002F Safe parse — no code execution\n",[121,202,203,205,207,209,213,216,219],{"class":123,"line":131},[121,204,135],{"class":134},[121,206,139],{"class":138},[121,208,142],{"class":134},[121,210,212],{"class":211},"sj4cs"," JSON",[121,214,215],{"class":138},".",[121,217,218],{"class":145},"parse",[121,220,221],{"class":138},"(window.myConfig)\n",[121,223,224],{"class":123,"line":171},[121,225,175],{"emptyLinePlaceholder":174},[121,227,228,230,232],{"class":123,"line":178},[121,229,181],{"class":138},[121,231,184],{"class":145},[121,233,187],{"class":138},[59,235,237],{"id":236},"remediation","Remediation",[239,240,241,246,256,267,270,276],"ol",{},[20,242,243,244,215],{},"Open each flagged tag and identify what string is passed to ",[27,245,38],{},[20,247,248,249,252,253,215],{},"If the string is a JSON payload: replace ",[27,250,251],{},"eval(str)"," with ",[27,254,255],{},"JSON.parse(str)",[20,257,258,259,262,263,266],{},"If the string is conditional logic: restructure using ",[27,260,261],{},"if\u002Felse"," or ",[27,264,265],{},"switch"," statements.",[20,268,269],{},"If the string originates from a URL parameter, cookie, or remote API: treat the tag as a potential XSS vulnerability and involve your security team before proceeding.",[20,271,272,273,275],{},"If the ",[27,274,38],{}," is from a vendor-supplied snippet: contact the vendor for a non-eval version, or use a native GTM tag template if one is available.",[20,277,278,279,281],{},"Test the refactored tag — ",[27,280,38],{}," is sometimes used to work around scope issues that will require explicit fixes.",[59,283,285],{"id":284},"metadata","Metadata",[287,288,291,292,297,291,301,305,291,308,312,291,315,318,291,321,325,291,328,332,291,338,341],"dl",{"className":289},[290],"spec-list","\n  ",[293,294,296],"dt",{"id":295},"severity","Severity",[298,299,300],"dd",{},"high",[293,302,304],{"id":303},"tier","Tier",[298,306,307],{},"error",[293,309,311],{"id":310},"category","Category",[298,313,314],{},"security",[293,316,317],{"id":50},"Layer",[298,319,320],{},"container",[293,322,324],{"id":323},"version","Version",[298,326,327],{},"1",[293,329,331],{"id":330},"effort","Effort",[298,333,334,337],{},[27,335,336],{},"2hr"," (about 2 hours)",[293,339,340],{"id":56},"Reversibility",[298,342,343],{},"non-destructive",[59,345,347],{"id":346},"see-also","See also",[17,349,350,358,365],{},[20,351,352,357],{},[353,354,356],"a",{"href":355},"\u002Fcategories\u002Fsecurity\u002F","Security rules"," — other rules in this category",[20,359,360,364],{},[353,361,363],{"href":362},"\u002Fhealth-score\u002F","Health score"," — how this rule contributes to the score",[20,366,367,371],{},[353,368,370],{"href":369},"\u002Frules\u002F","Rules catalog"," — browse all rules",[373,374,375],"style",{},"html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}",{"title":117,"searchDepth":131,"depth":131,"links":377},[378,379,380,381,382,383],{"id":61,"depth":131,"text":62},{"id":83,"depth":131,"text":84},{"id":102,"depth":131,"text":103},{"id":236,"depth":131,"text":237},{"id":284,"depth":131,"text":285},{"id":346,"depth":131,"text":347},[385,388,390],{"label":386,"href":387},"API Reference","\u002F",{"label":389,"href":369},"Rules",{"label":29},{"cards":392,"onpage":404},[393],{"title":394,"tabs":395},"Evaluate",[396,400],{"label":397,"language":398,"code":399},"cURL","bash","curl https:\u002F\u002Fdeveloper.tagmanifest.com\u002Fv1\u002Fevaluate-rule \\\n  -H \"Authorization: Bearer $TM_API_KEY\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\"rule_id\":\"eval-usage\",\"url\":\"https:\u002F\u002Fexample.com\"}'\n",{"label":401,"language":402,"code":403},"MCP","text","User: Run eval-usage on https:\u002F\u002Fexample.com\n\n# Tool call\n{\n  \"tool\": \"evaluate_rule\",\n  \"arguments\": {\n    \"rule_id\": \"eval-usage\",\n    \"url\": \"https:\u002F\u002Fexample.com\"\n  }\n}\n",[405,406,407,408,409],{"id":61,"label":62},{"id":83,"label":84},{"id":102,"label":103},{"id":236,"label":237},{"id":284,"label":285},null,"Tags use eval(), which executes arbitrary strings as code. This is a security risk (XSS vector) and prevents JavaScript engine optimizations.","md",{},"\u002Frules\u002Feval-usage","TechArticle",{"title":5,"description":411},"rules\u002Feval-usage",false,"4cusN4orcY_U_6YC6mVZflDSOcM5TCaC2KUKVFf4-Fw",1796069484427]