Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@datadog/native-iast-rewriter

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@datadog/native-iast-rewriter - npm Package Compare versions

Comparing version 0.1.0-beta.1 to 0.1.0-beta.2

39

js/source-map/index.js

@@ -9,5 +9,5 @@ 'use strict'

const pathSourceMapsCache = new Map()
const rewrittenSourceMapsCache = new Map()
function readAndCacheSourceMap (filename, filePath) {
const fileContent = fs.readFileSync(filename).toString()
function generateSourceMapFromFileContent (fileContent, filePath) {
const fileLines = fileContent.trim().split('\n')

@@ -27,3 +27,15 @@ const lastLine = fileLines[fileLines.length - 1]

if (rawSourceMap) {
const sm = new SourceMap(JSON.parse(rawSourceMap))
return new SourceMap(JSON.parse(rawSourceMap))
}
}
function cacheRewrittenSourceMap (filename, fileContent) {
const sm = generateSourceMapFromFileContent(fileContent, getFilePathFromName(filename))
rewrittenSourceMapsCache.set(filename, sm)
}
function readAndCacheSourceMap (filename, filePath) {
const fileContent = fs.readFileSync(filename).toString()
const sm = generateSourceMapFromFileContent(fileContent, filePath)
if (sm) {
if (pathSourceMapsCache.size >= CACHE_MAX_SIZE) {

@@ -38,8 +50,12 @@ pathSourceMapsCache.clear()

function getFilePathFromName (filename) {
const filenameParts = filename.split(path.sep)
filenameParts.pop()
return filenameParts.join(path.sep)
}
function getSourcePathAndLineFromSourceMaps (filename, line, column = 0) {
try {
let sourceMap = pathSourceMapsCache.get(filename)
const filenameParts = filename.split(path.sep)
filenameParts.pop()
const filePath = filenameParts.join(path.sep)
let sourceMap = rewrittenSourceMapsCache.get(filename) || pathSourceMapsCache.get(filename)
const filePath = getFilePathFromName(filename)
if (!sourceMap) {

@@ -49,7 +65,7 @@ sourceMap = readAndCacheSourceMap(filename, filePath)

if (sourceMap) {
const { originalSource, originalLine, originalColumn } = sourceMap.findEntry(line, column)
const { originalSource, originalLine, originalColumn } = sourceMap.findEntry(line - 1, column - 1)
return {
path: path.join(filePath, originalSource),
line: originalLine,
column: originalColumn
line: originalLine + 1,
column: originalColumn + 1
}

@@ -64,3 +80,4 @@ }

module.exports = {
getSourcePathAndLineFromSourceMaps
getSourcePathAndLineFromSourceMaps,
cacheRewrittenSourceMap
}

@@ -8,2 +8,3 @@ /**

const { getPrepareStackTrace } = require('./js/stack-trace/')
const { cacheRewrittenSourceMap } = require('./js/source-map')

@@ -16,5 +17,23 @@ class DummyRewriter {

let NativeRewriter
class CacheRewriter {
constructor (config) {
if (NativeRewriter) {
this.nativeRewriter = new NativeRewriter(config)
} else {
this.nativeRewriter = new DummyRewriter()
}
}
rewrite (code, file) {
const content = this.nativeRewriter.rewrite(code, file)
cacheRewrittenSourceMap(file, content)
return content
}
}
function getRewriter () {
try {
return require('node-gyp-build')(__dirname).Rewriter
NativeRewriter = require('node-gyp-build')(__dirname).Rewriter
return CacheRewriter
} catch (e) {

@@ -21,0 +40,0 @@ return DummyRewriter

{
"name": "@datadog/native-iast-rewriter",
"homepage": "https://github.com/DataDog/dd-native-iast-rewriter-js/blob/main/README.md",
"version": "0.1.0-beta.1",
"version": "0.1.0-beta.2",
"description": "Datadog IAST instrumentation addon for NodeJS",

@@ -6,0 +6,0 @@ "main": "main.js",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc