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

Changing to semantic CSP injection #131

Merged
merged 6 commits into from
Aug 19, 2016
Merged

Changing to semantic CSP injection #131

merged 6 commits into from
Aug 19, 2016

Conversation

MSLaguana
Copy link
Member

Instead of simply injecting some additional entries into the default-src of the csp, we now properly parse it and add the specific constraints that we care about. In particular, we make sure to preserve any previous constraints, but we allow websocket connections to 'self' and blob urls for images.

Fixes #130

Instead of simply injecting some additional entries into the default-src of the csp, we now properly parse it and add the specific constraints that we care about. In particular, we make sure to preserve any previous constraints, but we allow websocket connections to 'self' and blob urls for images.
@msftclas
Copy link

msftclas commented Aug 9, 2016

Hi @MSLaguana, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!


It looks like you're a Microsoft contributor (Jimmy Thomson). If you're full-time, we DON'T require a Contribution License Agreement. If you are a vendor, please DO sign the electronic Contribution License Agreement. It will take 2 minutes and there's no faxing! https://cla.microsoft.com.

TTYL, MSBOT;

// Note we replace "default-src 'self'" with "default-src 'self' ws:" (in Content Security Policy) so that
// websocket connections are allowed (this relies on a custom version of send that supports a 'transform' option).
// Note we add "connect-src 'self' ws:" and "img-src 'blob:' (in Content Security Policy) so that
// websocket connections are allowed and the camera plugin works (this relies on a custom version
Copy link
Collaborator

Choose a reason for hiding this comment

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

What do you mean that the camera plugin works? Is there any issue with that?

Copy link
Member Author

Choose a reason for hiding this comment

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

My understanding is that the camera plugin works by providing blob: URLs, and that's the reason for adding it to the CSP.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for the clarification.

var metaTagRegex = /<\s*meta[^>]*>/g;
var cspRegex = /http-equiv\s*=\s*(['"])Content-Security-Policy\1/;
var cspContent = /(content\s*=\s*")([^"]*)"/;
var maxCspTagLength = 1024;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe this could be declared only once at module level,

/**
 * Some doc if we need to clarify something.
 * @const
 */
var MAX_CSP_TAG_LENGTH = 1024;

@albertinad
Copy link
Collaborator

Looks good to me! thanks!

@MSLaguana MSLaguana merged commit be32fed into master Aug 19, 2016
@MSLaguana MSLaguana deleted the improveCspInjection branch August 19, 2016 20:18
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.

3 participants