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

Fix asset_uri_whitelist regex backtracking issue, add more extensions #270

Merged
merged 3 commits into from
Oct 25, 2023

Conversation

achim-k
Copy link
Collaborator

@achim-k achim-k commented Oct 24, 2023

Public-Facing Changes

Fix exponential regex backtracking issue with default asset_uri_whitelist

Description

When fetching the asset package://foxglove_simulation/meshes/kinect_jpg I noticed that I never got a response. It turned out that the reason for this was due to catastrophic backtracking caused by the default asset_uri_whitelist regular expression pattern. The default pattern contains nested quantifiers with alternations, which can lead to exponential backtracking. This can cause the program to hang or freeze when trying to match certain input strings.

This PR changes the default asset_uri_whitelist regex pattern to avoid catastrophic backtracking. It additionally adds a couple more extensions to e.g. allow for retrieval of texture files.

@achim-k achim-k requested a review from jtbandes October 24, 2023 18:51
Copy link
Member

@jtbandes jtbandes left a comment

Choose a reason for hiding this comment

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

👏

@jhurliman
Copy link
Contributor

Add TIFF and WEBP as well?

README.md Outdated
@@ -77,7 +77,7 @@ Parameters are provided to configure the behavior of the bridge. These parameter
* __send_buffer_limit__: Connection send buffer limit in bytes. Messages will be dropped when a connection's send buffer reaches this limit to avoid a queue of outdated messages building up. Defaults to `10000000` (10 MB).
* __use_compression__: Use websocket compression (permessage-deflate). Suited for connections with smaller bandwith, at the cost of additional CPU load.
* __capabilities__: List of supported [server capabilities](https://github.com/foxglove/ws-protocol/blob/main/docs/spec.md). Defaults to `[clientPublish,parameters,parametersSubscribe,services,connectionGraph,assets]`.
* __asset_uri_allowlist__: List of regular expressions ([ECMAScript grammar](https://en.cppreference.com/w/cpp/regex/ecmascript)) of allowed asset URIs. Uses the [resource_retriever](https://index.ros.org/p/resource_retriever/github-ros-resource_retriever) to resolve `package://`, `file://` or `http(s)://` URIs. Note that this list should be carefully configured such that no confidential files are accidentally exposed over the websocket connection. As an extra security measure, URIs containing two consecutive dots (`..`) are disallowed as they could be used to construct URIs that would allow retrieval of confidential files if the allowlist is not configured strict enough (e.g. `package://<pkg_name>/../../../secret.txt`). Defaults to `["package://(\w+/?)+\.(dae|stl|urdf|xacro)"]`.
* __asset_uri_allowlist__: List of regular expressions ([ECMAScript grammar](https://en.cppreference.com/w/cpp/regex/ecmascript)) of allowed asset URIs. Uses the [resource_retriever](https://index.ros.org/p/resource_retriever/github-ros-resource_retriever) to resolve `package://`, `file://` or `http(s)://` URIs. Note that this list should be carefully configured such that no confidential files are accidentally exposed over the websocket connection. As an extra security measure, URIs containing two consecutive dots (`..`) are disallowed as they could be used to construct URIs that would allow retrieval of confidential files if the allowlist is not configured strict enough (e.g. `package://<pkg_name>/../../../secret.txt`). Defaults to `["^package://(?:\w+/)*\w+\.(?:dae|stl|urdf|xacro|png|jpg|jpeg)$"]`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to add obj, mtl, fbx, glb, gltf to this default list?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, we could do that. Plus tiff and webp?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes please!

Copy link
Member

Choose a reason for hiding this comment

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

I thought Chrome didn't support tiff: https://stackoverflow.com/a/2177012/23649

Copy link
Member

Choose a reason for hiding this comment

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

Do these mtl, fbx, etc. files all have separate three.js loaders? I doubt they would be supported in studio out of the box, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought Chrome didn't support tiff: https://stackoverflow.com/a/2177012/23649

There is a special loader in three.js for TIFF support

Copy link
Contributor

Choose a reason for hiding this comment

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

Do these mtl, fbx, etc. files all have separate three.js loaders? I doubt they would be supported in studio out of the box, right?

Yes. MTL files accompany OBJ, and are supported by three.js along with FBX and GLTF (text and binary)

@achim-k achim-k changed the title Fix exponential regex backtracking issue with default asset_uri_whitelist Fix exponential regex backtracking issue with default asset_uri_whitelist, add more extensions Oct 24, 2023
Copy link
Member

@jtbandes jtbandes left a comment

Choose a reason for hiding this comment

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

Might want to add tif as an alias for tiff.

@achim-k achim-k changed the title Fix exponential regex backtracking issue with default asset_uri_whitelist, add more extensions Fix asset_uri_whitelist regex backtracking issue, add more extensions Oct 25, 2023
@achim-k achim-k enabled auto-merge (squash) October 25, 2023 14:46
@achim-k achim-k merged commit 4af6fa2 into main Oct 25, 2023
11 checks passed
@achim-k achim-k deleted the achim/fix-regex-backtracking-issue branch October 25, 2023 15:01
@achim-k achim-k mentioned this pull request Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants