-
Notifications
You must be signed in to change notification settings - Fork 43
Fix for Issue 1060 #1061
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for Issue 1060 #1061
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -88,16 +88,16 @@ function reset_form() { | |||||
| $('select').prop('selectedIndex',0); | ||||||
| $('input[type="file"]').hide(); | ||||||
| } | ||||||
| function select_add_option(s,opt) { | ||||||
| function select_add_option(s, opt, txt) { | ||||||
| var q = s.find('option').toArray().findIndex(function(x) { | ||||||
| if(x.value == opt) { | ||||||
| x.selected = true; | ||||||
| return true; } | ||||||
| }); | ||||||
| if(q < 0) { | ||||||
| s.append($('<option/>'). | ||||||
| attr({value: opt,selected: true}) | ||||||
| .html(opt)); | ||||||
| s.append($('<option/>') | ||||||
| .attr({value: opt,selected: true}) | ||||||
| .text(txt || opt)); | ||||||
| }; | ||||||
| } | ||||||
| function arrayReduce(arr,n) { | ||||||
|
|
@@ -515,11 +515,10 @@ function readFile(input) { | |||||
| //console.log(reader.result); | ||||||
| try { | ||||||
| if(input.id == "dtreecsvload") { | ||||||
| select_add_option($('#tree_samples'),file.name); | ||||||
| if(file.name.match(/\.json$/i)) | ||||||
| parse_json(reader.result) | ||||||
| else | ||||||
| parse_file(reader.result) | ||||||
| parse_file(reader.result, file.name); | ||||||
| } | ||||||
| else | ||||||
| tsv_load(reader.result) | ||||||
|
|
@@ -1442,88 +1441,121 @@ function create_export_schema_dtable(yi,x) { | |||||
| a[x[c]] = b | ||||||
| return a; },{})) | ||||||
| } | ||||||
| function parse_file(xraw) { | ||||||
| /* This is really parse csv instead of parse JSON */ | ||||||
| //var xraw = 'TSV data' | ||||||
| var zraw=[] | ||||||
| export_schema.decision_points = [] | ||||||
| export_schema.decisions_table = [] | ||||||
| /* CSV or TSV looks like | ||||||
| ID,Exploitation,Utility,TechnicalImpact,SafetyImpact,Outcome | ||||||
| */ | ||||||
| var xarray = xraw.split('\n') | ||||||
| var xr = xarray.map(x => x.split(/[\t,]+/)) | ||||||
| /* Remove first row has the headers and pass the rest to variable y */ | ||||||
| var y = xr.splice(1) | ||||||
| /* Check if rowID first column of second row to match not number*/ | ||||||
| var is_ssvc_v1 = y[0][0].match(/\D+/) ? false : true | ||||||
| /* Remove ID column in the first row to create x*/ | ||||||
| if (is_ssvc_v1) | ||||||
| var x = xr[0].splice(1) | ||||||
| else | ||||||
| var x = xr[0] | ||||||
| /* Now xr looks like below for ssvc csv v1 */ | ||||||
| /* [["Row", "Exploitation", "Virulence", "Technical", "Mission_Well-being", "Decision"]] */ | ||||||
| //var yraw = [[],[],[],[],[]] | ||||||
| /* Register the export schema decision points, assume all decisions are simple */ | ||||||
| export_schema.decision_points = x.map( | ||||||
| dc => { | ||||||
| var ix = {decision_type:"simple", options:[]} | ||||||
| ix.label = dc | ||||||
| return ix | ||||||
| }) | ||||||
| /* make the last column final decision/outcome/action */ | ||||||
| export_schema.decision_points[export_schema.decision_points.length-1].decision_type="final" | ||||||
| /* Initialize Empty arrray */ | ||||||
| var yraw = [...Array(x.length)].map(u => []); | ||||||
| var id=1; | ||||||
| /* This will create just the last branches of the tree */ | ||||||
| var thash = {} | ||||||
| for(var i=0; i< y.length - 1; i++) { | ||||||
| if(y[i].length < 1) continue | ||||||
| /* Remove ID column if it is SSVC v1*/ | ||||||
| if(is_ssvc_v1) | ||||||
| y[i].shift() | ||||||
| /* Add lame CSV/TSV data to export schema */ | ||||||
| //console.log(y[i]); | ||||||
| create_export_schema_dtable(y[i],x) | ||||||
| var tname = y[i].pop()+":"+y[i].join(":") | ||||||
| //console.log(tname) | ||||||
| if(tname == "undefined") continue; | ||||||
| for( var j=0; j< x.length-1; j++) { | ||||||
| /*y[i] look like 0,none,laborious,partial,none,defer */ | ||||||
| var tparent = x[x.length-2-j]+":"+y[i].slice(0,x.length-2-j).join(":") | ||||||
| //console.log(tparent) | ||||||
| if(!(tname in thash)) | ||||||
| var yt = {name:tname.replace(/\:+$/,''),id:id++,parent:tparent.replace(/\:+$/,''),props:"{}",children:[]} | ||||||
| else | ||||||
| continue | ||||||
| thash[yt.name] = 1 | ||||||
| tname = tparent | ||||||
| yraw[j].push(yt) | ||||||
| } | ||||||
| } | ||||||
| /* This step below is not necessary now as the above routine goes from | ||||||
| 0 -> y.length, instead of 0 to y.length -1. | ||||||
| Remove ID column and Add the last row into export schema */ | ||||||
| //y[y.length-1].shift() | ||||||
| //create_export_schema(y[y.length-1],x) | ||||||
| for(var j=yraw.length; j> -1; j--) { | ||||||
| if(yraw.length > 0) | ||||||
| zraw = zraw.concat(yraw[j]) | ||||||
| } | ||||||
| /* Next part of the tree data */ | ||||||
| zraw[0] = {name:x[0],id:id+254,children:[],parent:null,props:"{}"} | ||||||
| /* yraw[0].push({name:"Exploitation:",id:1024,children:[],parent:null,props:"{}"}) */ | ||||||
| raw = zraw | ||||||
| var detect_version = "v2" | ||||||
| if(is_ssvc_v1) | ||||||
| detect_version = "v1" | ||||||
| topalert("Decision tree has been updated with "+raw.length+" nodes, with "+ | ||||||
| y.length+" possible decisions using "+detect_version+" CSV/TSV file, You can use it now!","success") | ||||||
| dt_clear(); | ||||||
| export_schema.decision_points[export_schema.decision_points.length-1]. | ||||||
| options.map((x,i) => lcolors[x.label] = ocolors[i] ) | ||||||
| function uniquePrefix(str, used) { | ||||||
| let key = str[0]; | ||||||
| let j = 2; | ||||||
| while (used[key]) { | ||||||
| key = str.substr(0, j); | ||||||
| j++; | ||||||
| } | ||||||
| used[key] = str; | ||||||
| return key; | ||||||
| } | ||||||
| function parse_file(xraw, filename) { | ||||||
| if (!filename) filename = "file"; | ||||||
|
|
||||||
| const namespace = "x_example.test#importedfile"; | ||||||
| const version = "1.0.0"; | ||||||
| const schemaVersion = "2.0.0"; | ||||||
|
|
||||||
| const imported = { | ||||||
| displayname: "Imported: " + filename, | ||||||
| data: { | ||||||
| namespace: namespace, | ||||||
| decision_points: {}, | ||||||
| mapping: [], | ||||||
| name: "Imported file " + filename, | ||||||
| key: "IMP_1", | ||||||
| definition: "Imported file " + filename, | ||||||
| version: version, | ||||||
| schemaVersion: schemaVersion | ||||||
| } | ||||||
| }; | ||||||
|
|
||||||
| const xarray = xraw.split("\n").filter(Boolean); | ||||||
|
||||||
| const xarray = xraw.split("\n").filter(Boolean); | |
| const xarray = xraw.split(/\r?\n/).filter(Boolean); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will be included in the next commit
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid automated semicolon insertion (95% of all statements in the enclosing function have an explicit semicolon).
| let detect_version = "CSVv1" | |
| let detect_version = "CSVv1"; |
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Headers and values from an imported file are treated as trusted strings and later rendered in the UI; parse_json uses .html(...) for some label rendering, so a malicious header/value could inject HTML/JS. Either sanitize/escape imported headers/values before building the schema, or change the downstream rendering to use .text(...) for user-controlled content.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will update parse_json to change html to text
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console.log(imported) will log the entire imported decision tree (including potentially sensitive local file contents) in production. Consider removing this or gating it behind an explicit debug flag.
| console.log(imported); |
Uh oh!
There was an error while loading. Please reload this page.