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

load all assets from localhost to set origin properly #387

Merged
merged 7 commits into from
Jan 15, 2022

Conversation

mbektas
Copy link
Member

@mbektas mbektas commented Jan 7, 2022

  • Loads initial content from http://localhost:port/desktop-app-assets/index.html to be able to set window.origin properly
  • Fixes issues related to Electron 15 upgrade

Copy link
Member

@krassowski krassowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks super exciting, looking forward to having this in!

While I see that this is still draft, I left some general comments to remember about these aspects later on.

src/main/main.ts Outdated Show resolved Hide resolved
const assetFilePath = path.join(appAssetsDir, assetPath);
const assetContent = fs.readFileSync(assetFilePath);
callback(assetContent);
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you elaborate on what is happening in the else clause? My current understanding is that the if () clase is for hosting static assets and else assumes that if it is not a static asset, then this is a server request and modifies cookies and handles file upload, but it is not clear to me why specific parts are needed.

Should we split up the handler code into separate methods to better signal the intent and have easier time in the future?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, you are right. since interceptBufferProtocol doesn't provide a default callback handler, we are having to make the requests to JupyterLab server in the else section. During my experiments, I found out that cookies were not properly set for some of the requests (websocket handshake?). So, to be on the safe side, I am setting them with both this._window.webContents.session.cookies.set(cookieObject); and requestHeaders['Cookie'] = Array.from(cookies.values()).join('; '); for every request. I am not sure at the moment how we can optimize this.

if (qMark !== -1) {
assetPath = assetPath.substring(0, qMark);
}
const assetFilePath = path.join(appAssetsDir, assetPath);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if assets path includes ..? That could potentially escalate access to filesystem. I think that we need to be very stringent here and check that the new assetFilePath is a child of appAssetsDir.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also hard-code a list of static files that the client is allowed to access.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if asset path can include ... we are calculating it from request url. but still, It makes sense to check if assetFilePath is a child of appAssetsDir, good idea.

@mbektas mbektas marked this pull request as ready for review January 13, 2022 04:00
Comment on lines +39 to +42
const appConfig: IAppConfiguration = {
jlabPort: 8888,
token: 'jlab-token'
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I anticipate that a hard-coded global will cause issues once we will go for full front/back separation. But I am happy to address it myself later.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, we can definitely improve this when we support remote backends etc. by the way, these are just default values and token is generated on the fly before server launch.

Copy link
Member

@krassowski krassowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@mbektas mbektas merged commit fc840df into master Jan 15, 2022
@mbektas mbektas mentioned this pull request Jan 15, 2022
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

Successfully merging this pull request may close these issues.

2 participants