Skip to content
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

Slack 4.0.0 doesn't contain src/static/ssb-interop.js #51

Open
sammorley-short opened this issue Jul 11, 2019 · 80 comments
Open

Slack 4.0.0 doesn't contain src/static/ssb-interop.js #51

sammorley-short opened this issue Jul 11, 2019 · 80 comments

Comments

@sammorley-short
Copy link

I just tried to install this for Slack 4.0.0 (downloaded via the Mac OSX App Store) and it failed to find the correct file.

When I searched the file directory, no ssb-interop.js file was found:

Slack.app $ sudo find . -name '*.js'                                                                                                                                                                                                                                                                       
Password:
./Contents/Resources/app.asar.unpacked/dist/static/extensions/react-devtools/popups/shared.js
./Contents/Resources/app.asar.unpacked/dist/static/extensions/react-devtools/build/background.js
./Contents/Resources/app.asar.unpacked/dist/static/extensions/react-devtools/build/backend.js
./Contents/Resources/app.asar.unpacked/dist/static/extensions/react-devtools/build/panel.js
./Contents/Resources/app.asar.unpacked/dist/static/extensions/react-devtools/build/main.js
./Contents/Resources/app.asar.unpacked/dist/static/extensions/react-devtools/build/inject.js
./Contents/Resources/app.asar.unpacked/dist/static/extensions/react-devtools/build/contentScript.js

Any ideas which file to point it to instead?

@sdbuch
Copy link

sdbuch commented Jul 19, 2019

A colleague provided a link to this issue in another repo, where the same problem has been solved. It seems (at least on OSX) one needs to have npm installed, and then one can unpack the .asar file in Slack 4.0 using npx, inject math-with-slack, then repack it.

@fsavje
Copy link
Owner

fsavje commented Jul 19, 2019

I will take a look at this as soon as possible, but that will unfortunately be a few weeks.

@fsavje fsavje pinned this issue Jul 19, 2019
@fsavje
Copy link
Owner

fsavje commented Jul 22, 2019

Took a look at this today. Turns out that Slack has added a Content Security Policy to avoid script injections. One can inject meta tags in the webapp by unpacking and repacking the asar file as suggested by @hwagyesa . However, it does not load the MathJax script from the CDN:

/Applications/Slack.app/Contents/Resources/app.asar/dist/ssb-interop.bundle.js:40
Refused to load the script 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js' because it violates the following Content Security Policy directive:
"script-src 'self' https://a.slack-edge.com/ https://cfr.slack-edge.com/ https://fst.slack-edge.com/ 'sha256-HtosUFirHdHvZwGXLdjtfHXYVEjfNmDyX7ffscLm7qw=' 'sha256-V3pNBo9vFI47lnzeFlyJVDxtN3Yf0X6UgalmXzoA69U=' 'sha256-XVjf1UrB+S9bTulVsVW6RjmlY9eDXYYpMiNpLNbVBC0=' 'sha256-F1YT8S1ELkeOyM7rwIMIkVMS8a8FVeXoxmlDjUWZ7Rw=' 'sha256-bnzwnkVhpJR3UZDeyqmzR5+Vty3+pxQYDebbeatN4pU=' 'sha256-NKJOlWPHN59LLYioFQrsjETUtZ+C2AH7plCQfLp7ItY=' 'sha256-D+/bcNwAmFYJ9CfMh57ykwI2161k02TzQhHgIuPRv0I=' 'sha256-jvnF/vs0XdFoP8ZslmhYkCiX84ifYfYKhsPLItnQ+po=' 'sha256-r04w7sZJG0w7qP3YQWJQqrWEAltzCG24RNqrNlDmL6o=' 'sha256-G47a8SPvyDeMvcflK35cUDWqZ6qVRoCf5Z3K0evCOzU=' 'sha256-gZRnrJgs9oG1IkDd5eWANg4/vxp66C0/LYib66mK6Ng=' 'sha256-UvgDsssAGwGDwJDr31x/G3Q7Fuy1B7S5Fw1uHsgBKlE=' 'sha256-sPqPkLDIPKNAk2Vqyp4vscB38LWqm07HVzPEUq6lct4=' 'sha256-5DB6q76v13BY+HEvVt9XeNU1zDEeA4U0De5HHiib54U=' 'sha256-Tu41NFywTKucDrnDukVaLIvsMTz7LqDJswN066TfHNQ=' 'sha256-M+GeuEwdHgLK+IB+9Hmhf8mIrHIv6oKp7xEfGJGmmPY='".

As I've understood it, it isn't possible to modify the CSP on the run, so it seems that using a CDN for script delivery is out of the picture. I also tried injecting a local copy of MathJax, but it was ignored because it wasn't in the electron manifest (and I'm unsure whether it would circumvent the CSP in any case). I guess it technically would be possible to inject the full MathJax library in the same way as the meta tags are injected now, but that is not feasible given that MathJax is over 100 mb.

Does anyone have any ideas on a way forward on this?

@sdbuch
Copy link

sdbuch commented Jul 22, 2019

The unpack-inject-repack scheme is working for me in the latest version of App Store Slack provided I follow the suggestion in this comment before injecting. There is some discussion of this issue here, but it seems it is unclear why changing this setting helps. When using the version of the app downloaded from Slack's website, the unpack-inject-repack scheme was working for me even without changing the bootSonic setting. Based on the information you've posted, though, it looks like this kind of workaround likely won't be viable for long.

@fsavje
Copy link
Owner

fsavje commented Jul 22, 2019

@hwagyesa Could you clarify: do you manage to get math-with-slack running with this method or slack-dark-mode?

@sdbuch
Copy link

sdbuch commented Jul 22, 2019

@fsavje Both math-with-slack and slack-dark-mode work for me (and at least one of my colleagues) with this method. The script I am using with math-with-slack can be found in my fork of the repository.

@fsavje
Copy link
Owner

fsavje commented Jul 23, 2019

Thanks!

Seems this route will work on Mac OS at least. If anyone tests it out on Linux or Windows, please report the results here.

Working on a python script to avoid installing Node.js. In the meanwhile, manually unpacking and packing app.asar using node.js will work.

@bangconghuynh
Copy link

@hwagyesa's route works on Linux too.

@Dr-Irv
Copy link

Dr-Irv commented Jul 27, 2019

I have Windows, but @hwagyesa didn't update the Windows version of the install script, so I can't test it. Looking forward to your python script install

@erikvannimwegen
Copy link

Dear fsavje,
would it be possible to write a description for non-experts on how to get math-with-slack working on Mac OSX? We use an enormous amount of latex in our slack discussions and since the last update of Slack our life has been a misery. I understand from your exchange with hwagyesa that there is a solution for Mac OS but the description is too technical for me to understand what I need to do to get it working. Thanks so much!

@fsavje
Copy link
Owner

fsavje commented Aug 7, 2019

Hi @erikvannimwegen. I don't know if I can give anymore detailed instructions than those by @hwagyesa. However, I hope to have a draft version of the updated script up during the weekend.

@erikvannimwegen
Copy link

Ok great.. if there will be an updated version soon then I guess I don't need to learn.
But just so know, for a lay user it is completely unclear what it means to 'unpack' an .asar file (or what .asar file @hwagyesa refers to), how to do this unpacking 'in Slack 4.0', how to then 'inject' the script, or how to then 'repack it' afterwards (or even what precisely 'it' is in this context). I understand that I could research online until I do know what these things are, but I guess I was hoping there was a way to give 4 or 5 concrete command line commands that together would accomplish those steps. Thanks in any case for the extremely valuable plugin.

@sdbuch
Copy link

sdbuch commented Aug 7, 2019

Dear @erikvannimwegen, you can perform the following steps to use my script, working for me and others on OSX:

  1. Run in a terminal brew install npm (download Homebrew if you don't have it);
  2. Clone my fork of @fsavje's math-with-slack repository;
  3. Run the math-with-slack.sh script like usual.

The quality of my code is much worse than @fsavje's. If this seems problematic you may wait for his upcoming script.

@fsavje
Copy link
Owner

fsavje commented Aug 7, 2019

A draft version of the python script is up now: https://github.com/fsavje/math-with-slack/tree/v3 It should work with both Python 2.7 and 3. It has, however, not been tested on Windows or Linux. Please let me know if it doesn't work.

It seems that Slack 4.0.1 overwrites the local settings JSON file. Any ideas on circumvent this would be welcomed.

@rcurr
Copy link

rcurr commented Aug 8, 2019

@fsavje I've had a quick try with "math-with-slack.py" on Ubuntu 16.04 and haven't been able to get it to work.

I'm using the slack/slack-desktop packages (version 4.0.1) from the https://packagecloud.io/slacktechnologies/slack/debian/ repository (originally from https://slack.com/downloads/linux). I've ran the script and it changes app.asar. "grep fsavje app.asar" matches, though if I unpack then file with "npx asar extract app.asar /tmp/extract" the "ssb-interop.bundle.js" file is missing.

Some things I noticed with the script:

  • "sys.platform == 'linux'" won't work with python 2.7 on my platform, sys.platform returns "linux2". Perhaps use "sys.platform.startswith('linux')"?
  • If the user has not yet launched slack, the local-settings.json file may not yet exist for them. At the moment it seems that he script won't run on Linux if that file doesn't exist.
  • Can you add an option to not create the .mwsbak file?

@Dr-Irv
Copy link

Dr-Irv commented Aug 8, 2019

I submitted a pull request #53 to make the python script work with Windows.

@claresinger
Copy link

A draft version of the python script is up now: https://github.com/fsavje/math-with-slack/tree/v3 It should work with both Python 2.7 and 3. It has, however, not been tested on Windows or Linux. Please let me know if it doesn't work.

Hi, I'm using Mac OSX. Running your .py script gives me this permission denied error. How can I make sure the script has write permissions?

[Errno 13] Permission denied: '/Applications/Slack.app/Contents/Resources/app.asar.mwsbak'
Cannot make backup. Make sure the script has write permissions.

@terasakisatoshi
Copy link

I've got the following error even the latest releases.
An error message ✘ Cannot find Slack installation. shows on my Mac terminal

@terasakisatoshi
Copy link

Ah ... Sorry.

I should have tried the script below:
https://github.com/fsavje/math-with-slack/blob/v3/math-with-slack.py

just run

$ sudo python math-with-slack.py
sudo python mathwiths.py 
Using Slack installation at: /Applications/Slack.app/Contents/Resources/app.asar
Using local settings file at: /Users/myuser/Library/Containers/com.tinyspeck.slackmacgap/Data/Library/Application Support/Slack/local-settings.json
Install successful. Please restart Slack.

works for me. Thank you @fsavje

@thisiscam
Copy link

thisiscam commented Sep 9, 2019

It seems that Slack 4.0.1 overwrites the local settings JSON file. Any ideas on circumvent this would be welcomed.

My temporary fix was to hijack /Applications/Slack.app/Contents/MacOS/Slack.

Basically, create rename this Slack executable to Slack_bk, then create a shell script in place of that:

#!/bin/sh
# Contents for /Applications/Slack.app/Contents/MacOS/Slack

tmp_dir=$(mktemp -d)
prev_dir=$(pwd)
cd $tmp_dir
curl -O https://github.com/fsavje/math-with-slack/blob/v3/math-with-slack.py
python math-with-slack.py
cd $prev_dir
rm $tmp_dir

script_path="$( cd "$(dirname "$0")" ; pwd -P )"

exec "${script_path}/Slack_bk" "$@"

Make it executable:

chmod +x /Applications/Slack.app/Contents/MacOS/Slack

@alanocallaghan
Copy link

alanocallaghan commented Oct 9, 2019

Trying this on Ubuntu 18.04.3 now, running just the python file I get:

sudo python ./math-with-slack.py 
Could not find Slack's app.asar file. Please provide path.

if I supply the app file I get a missing local settings file:

sudo python ./math-with-slack.py -a /usr/lib/slack/slack
Could not find local-settings.json. Please provide path.

I can't find any info on where this file might be on Ubuntu.

EDIT: this call seems to have worked for me, in case it helps anyone:

sudo python ./math-with-slack.py -a /usr/lib/slack/resources/app.asar -s /home/alan/.config/Slack/local-settings.json

@alanocallaghan
Copy link

Actually it ran successfully but didn't change anything.

@PeganovAnton
Copy link

Actually it ran successfully but didn't change anything.

Same on Ubuntu 16.04

@PeganovAnton
Copy link

Hello! I also have a problem with unpacking app.asar.

user@host:~$ npx  asar --verbose extract /usr/lib/slack/resources/app.asar asar_extracted/
npx: installed 21 in 2.442s
Unexpected token function

@pturne7
Copy link

pturne7 commented Oct 24, 2019

A draft version of the python script is up now: https://github.com/fsavje/math-with-slack/tree/v3 It should work with both Python 2.7 and 3. It has, however, not been tested on Windows or Linux.

Has anyone successfully used this script for Windows? When I run it in Python Shell, I receive a message saying `Not implemented,' and that's it.

I would appreciate input from anyone who has successfully installed math-with-slack on Windows following the recent protections against code injections.

@alanocallaghan
Copy link

The not implemented message means just that; nobody's implemented the functionality in the script on Windows.

@Dr-Irv
Copy link

Dr-Irv commented Oct 24, 2019

@pturne7 I submitted a pull request at #53 that makes it work on Windows.

I believe that if you download the file math-with-slack.py from here: https://github.com/fsavje/math-with-slack/blob/d15ce28d8394f8a021b88d793a222b80e8566b28/math-with-slack.py

then you'll be able to run it on Windows.

@abogatskiy
Copy link

abogatskiy commented Dec 8, 2019

Slack 4.2.0 seems to have finally killed the python script as well (I'm on Mac). The error is KeyError: 'ssb-interop.bundle.js'. And Slack stops launching after this.

@thisiscam
Copy link

sorry, I was printing errors and warning only…
now I attach the log since there are different elements returned before the error depending on where it happens…
app.slack.com-1585052704374.log

I'm not really sure what's happening. Given that Slack just updated on Mac, is it possible you are seeing this because of a new slack version (e.g. 4.3.3 is new on Ubuntu 18)?

@julou
Copy link

julou commented Mar 25, 2020

Alright, updated slack, run your new py script.
Same problem still…

So I played a bit to understand when the rendering started failing. I can trigger the issue by entering a line which contains only a latex formula. then all rendering in the current slack session is gone. If Slack is restarted, rendering works fine until the block containing this line is met, then no more rendering until new slack relaunch…

by the way, both single and double $ formula trigger it.

Hope you can reproduce it on your side!

@erikvannimwegen
Copy link

I can confirm this behavior. The key is that one has to enter a line that has ONLY a latex formula, i.e. no other text before or after it. This then breaks all rendering. A restart can fix it as long as one avoids trying to render such a 'latex only' line.

@julou
Copy link

julou commented Mar 25, 2020

I have pushed a fix that should support both the 4.3.3 and 4.4.1 here (script url same as before)

btw I had to install the python packaging module to run this one. Not sure whether this what intended or overlooked…

@thisiscam
Copy link

I have pushed a fix that should support both the 4.3.3 and 4.4.1 here (script url same as before)

btw I had to install the python packaging module to run this one. Not sure whether this what intended or overlooked…

Sorry, I thought that was built-in. Should be fixed by now

@thisiscam
Copy link

thisiscam commented Mar 25, 2020

@erikvannimwegen @julou So this is on Ubuntu 18, and an example single line formula as in $x$? Is this in the person-to-person chat view, or the thread view (the right panel)?

I don't think I'm able to reproduce this in any ways above on a Mac. Maybe it's time to invoke my virtual machine

@thisiscam
Copy link

I think I found something. The log @julou sent contains typesetting of elements with class div.p-rich_text_block.p-rich_text_block--inline --- something I've not seen on my OSX Slack. The p-rich_text_block--inline is particularly suspicious. Can you try to locate a div with formula that has this class attribute (presumably it should be a div that breaks rendering), and send a screen shot for what that div looks like ?

@thisiscam
Copy link

Update: Ubuntu 16 + Slack 4.4.0 via Debian renders fine.

@thisiscam
Copy link

thisiscam commented Mar 25, 2020

@erikvannimwegen @julou Can you try the newest version? I pushed a fix that might solve your problem (likely not, but worth a try)

@julou
Copy link

julou commented Mar 26, 2020

hi @thisiscam
thanks for caring about the issue!

I tried your newest version (using Slack 4.4.1 on MacOS 10.14.6). The problem is not solved yet, and occurs both on thread and person-to-person chat.

But another example from @erikvannimwegen helped me specified better what triggers the bug:
the rendering stops after trying to render a formula on a latex-only line which is not the first line of the post.

This renders fine

$a nice latex equation$

This stops all rendering after being displayed (for any latex formula in slack).

we model the process assuming
$a nice latex equation$

Please let me know if you can reproduce the issue on your mac, otherwise I will try to create a log for a problematic case.

@julou
Copy link

julou commented Mar 26, 2020

btw I had to install the python packaging module to run this one. Not sure whether this what intended or overlooked…

Sorry, I thought that was built-in. Should be fixed by now

I tried after uninstalling packaging and it indeed works :)

@thisiscam
Copy link

thisiscam commented Mar 26, 2020

But another example from @erikvannimwegen helped me specified better what triggers the bug:
the rendering stops after trying to render a formula on a latex-only line which is not the first line of the post.

I can reproduce this now.

@julou Looking at mathjax/MathJax#2202, I fixed the problem by simply updating MathJax to 3.0.1 . You can try the updated script and see if it works for you?

@julou
Copy link

julou commented Mar 26, 2020

yeah… it works! 🍾🍾🍾
Thank you for your patience… I'd never had thought that it could be a bug in mathjax itself!

@abogatskiy
Copy link

abogatskiy commented May 27, 2020

Not able to get it to work with Slack 4.6.0 (macOS Catalina). The script runs successfully but has no effect.

@mdmilgrom
Copy link

Not able to get it to work with Slack 4.6.0 (macOS Catalina). The script runs successfully but has no effect.

I had the same experience. I was concerned when the release notes said the app sandbox was now enabled for all web content that Jax would be broken, and I should have trusted that instinct. I had it up and running for less than a day.

@thisiscam
Copy link

Yes I can confirm that Slack 4.6.0 breaks this. One way around is maybe to somehow inject mathjax as a webpack transpiled module into the preload script.. it will be horribly large though and I'm not sure about its feasibility.

Any suggestions are welcomed!

@thisiscam
Copy link

Ok I pushed a commit thisiscam@80112ad, that includes an inline source of MathJax into preload.js.
Things seems to be working, though not sure how much of performance impact it has on rendering/opening a new page.

@mdmilgrom
Copy link

mdmilgrom commented May 28, 2020

Never mind: wget downloaded the HTML, not the python script. I love when Github does that.
When I run the latest commit of math-with-slack.py with sudo python math-with-slack.py on MacOS 10.15.4, I get:

  File "math-with-slack.py", line 6
    <!DOCTYPE html>
    ^
SyntaxError: invalid syntax

@YingzhouLi
Copy link

YingzhouLi commented Jul 3, 2020

@thisiscam, does your version works for Slack 4.7?
I also suggest we close this issue and open ones for different versions of Slack. Then the discussion would be more clear.

@thisiscam
Copy link

@YingzhouLi it is working for me. FYI I'm not the owner of this repo (so I can't close an issue or merge PR). If there are specific questions related to my fork, all are welcomed to leave issues there!

@YingzhouLi
Copy link

YingzhouLi commented Jul 4, 2020

@thisiscam Thanks. Your forked master branch works on my Ubuntu 20.04 with Slack 4.7.0. The code works for Windows as well. I have slightly modified the path search part for Windows in my fork. The readme is also updated slightly. If you prefer, I do a pull request back into your repo.

@joaompereira
Copy link

@thisiscam Thanks. Your forked master branch works on my Ubuntu 20.04 with Slack 4.7.0. The code works for Windows as well. I have slightly modified the path search part for Windows in my fork. The readme is also updated slightly. If you prefer, I do a pull request back into your repo.

This code is working for me as well, I have Windows and Slack 4.7.0. The search path for app.asar is implemented correctly. The only thing missing is having a version of this code not in Python, for those people that don't have Python installed.

Thank you very much!

@Dr-Irv
Copy link

Dr-Irv commented Aug 11, 2020

@YingzhouLi I tried your fork on Windows 10, with Slack 4.8 and it worked. You might want to make the instructions more clear that you want to say "yes" to the most recent slack installation, because if you say "yes" to the oldest, it never prompts you for the newest. It turned out I had folders for both slack 4.7 and 4.8, and couldn't figure out why it wasn't working until I studied your script.

@thisiscam
Copy link

@YingzhouLi If you can submit a PR to my repo, I will merge in your changes. Thanks!

@YingzhouLi
Copy link

@Dr-Irv Thank you for the suggestion. I have revised the interface to select among multiple versions of Slack. (It seems that new Slack installation will also remove old versions from Windows.)
@thisiscam I have submitted a pull request to your repo.

@Yuren-Zhong
Copy link

Is there any version that works on Mac with Slack 4.8.0 ??

@Dr-Irv
Copy link

Dr-Irv commented Sep 10, 2020

@Yuren-Zhong Try this fork https://github.com/YingzhouLi/math-with-slack . It worked for my colleague who has slack 4.8 on Mac

@julou
Copy link

julou commented Sep 10, 2020

Is there any version that works on Mac with Slack 4.8.0 ??

https://github.com/thisiscam/math-with-slack works for me on Mac with Slack 4.8.0

@mdmilgrom
Copy link

mdmilgrom commented Sep 10, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests