Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

De-obfuscate JavaScript with source-map in PHP

We have an JavaScript page in production that catches any exceptions and logs them to our database. This worked fine for a while, but now we use uglifyjs to obfuscate the code and this also obfuscates the stack trace.

I know Firefox and Chrome can de-obfuscate but it does not help us since we want to de-obfuscate exceptions that ocured in production.

We have the source-map so what I would like to do is have our backend (php) recive the exception and de-obfuscate it with the source-map before logging it to the database.

I know the Mozilla Source-map project can do this for node.js, but is there a way to do it in PHP ?

like image 577
Eystein Bye Avatar asked Oct 22 '25 13:10

Eystein Bye


1 Answers

We figured out the koala-framework has done an implementation of (de)obfuscating of source maps in PHP.

Add koala-framework/sourcemaps as dependency via composer ( https://packagist.org/packages/koala-framework/sourcemaps )

https://github.com/koala-framework/sourcemaps

For deobfuscating you are interested in Kwf_SourceMaps_SourceMap(source_map) and getMappings() afterwards.

like image 78
norrs Avatar answered Oct 24 '25 02:10

norrs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!