
Research
/Security News
Critical Vulnerability in NestJS Devtools: Localhost RCE via Sandbox Escape
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
adiff is a minimal implementation of diff tools, diff, patch, diff3 in javascript.
I initially started writing this to understand how git works. then i got totally carried away. adiff is a central component in snob a self hosting port of git to javascript.
if you want to know what is the difference between two files, you must first know what is the same.
this is called the Longest Common Subsequence problem. if you have two sequences x = "ABDCEF" and
y = "ABCXYZF"then
LCS(x,y)` is clearly "ABCF".
function lcs (a,b)
if head(a) == head(b)
then lcs(a,b) = head(a) + lcs(tail(a), tail(b))
else lcs(a, b) = max(lcs(tail(a),b), lcs(a, tail(b)))
(where max returns the longer list, head return the first element, and tail returns the rest of the sequence minus the head)
this is very simple, but with exponential time complexity. however, it can easily be made sufficantly performant by cacheing the return value of each call to lcs().
see js implementation, index.js#L64-94
now, we can see when the strings differ, by comparing them to the lcs. the next step is dividing them into 'stable' chunks where they match the lcs, and unstable chunks where they differ.
basically, to go from chunk("ABDCEF", "ABCXYZF")
to
["AB", ["D", ""], "C", ["E", "XYZ"], "F"]
note that stable and unstable chunks always alternate.
basically, you iterate over the sequences and while the heads match the head of the lcs, shift that value to a stable chunk. then, while the heads do not match the next head of the lcs, collect add those items into an unstable chunk.
once you have the chunks getting a list of changes that you can apply is easy...
making a diff from a to b we want to know what changes to make to a to get b.
the way I have node this Array#splice
so, for ["AB", ["D", ""], "C", ["E", "XYZ"], "F"]
we want:
var changes = [
[4, 1, 'X', 'Y', 'Z'], //delete 1 item ("E") at index 4, then insert "X", "Y", "Z"
[2, 1] //delete 1 item at index 2 ("D")
]
note, you can apply changes to the end of the array without altering the indexes in the start of the array.
this makes the function to apply the patch very simple
function patch (orig, changes) {
var ary = orig.split('') //assuming that orig is just a string
changes.forEach(function (ch) {
[].splice.apply(ary, ch)
})
return ary.join('')
}
if we want a distributed version management system, the we need to be able to make changes in parallel.
this is only a slightly more complicated problem. given a string "ABDCEF"
, If I changed it to "ABCXYZF"
and meanwhile you changed it to "AXBCEFG". we must compare each of our changes to the original string, the Concestor
TODO: worked example with chunks, resolve.
MIT / Apache2
FAQs
diff and patch arrays.
The npm package adiff receives a total of 1,794 weekly downloads. As such, adiff popularity was classified as popular.
We found that adiff demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.