Skip to content

Conversation

mhaddy
Copy link
Contributor

@mhaddy mhaddy commented Feb 20, 2018

Utilize appendUntrusted() to safely escape any content from the user (e.g., malicious HTML or javascript).

Utilize  appendUntrusted() to safely escape any content from the user (e.g., malicious HTML or javascript).
Copy link
Member

@nelsonic nelsonic left a comment

Choose a reason for hiding this comment

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

@mhaddy looks good. 👍
(only thing I would change is the name of the function from cleanMe to santize for clarity)

@mhaddy
Copy link
Contributor Author

mhaddy commented Feb 20, 2018

Excellent! @nelsonic do you want me to make the updates?

// sanitize content from the user - trust no one
// ref: https://developers.google.com/apps-script/reference/html/html-output#appendUntrusted(String)
function cleanMe(theunclean) {
var output = HtmlService.createHtmlOutput(theunclean);
Copy link
Collaborator

Choose a reason for hiding this comment

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

this line is not used.

// for every key, concatenate an `<h4 />`/`<div />` pairing of the key name and its value,
// and append it to the `result` string created at the start.
}
return result; // once the looping is done, `result` will be one long string to put in the email body
}

// sanitize content from the user - trust no one
// ref: https://developers.google.com/apps-script/reference/html/html-output#appendUntrusted(String)
function cleanMe(theunclean) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree with @nelsonic, let's try and clean up the names here. e.g. sanitizeFormResult(rawResult), or something along those lines

// ref: https://developers.google.com/apps-script/reference/html/html-output#appendUntrusted(String)
function cleanMe(theunclean) {
var output = HtmlService.createHtmlOutput(theunclean);
var placeholder = HtmlService.createHtmlOutput(' ');
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would use an empty string here to "save space", granted that is probably negligible. Also, code convention in the repo is to use double quotes, i.e. ""

Copy link
Collaborator

@mckennapsean mckennapsean left a comment

Choose a reason for hiding this comment

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

Overall, I like the improvements made here. Thank you for the contribution!

As a note, this could break existing forms if people upgrade the server-side code. Namely, if they were using this feature to say, add images or custom HTML elements from the client and sending that to the server. I know of no one who has, but you could send all sorts of things, from images to possibly SVG visualizations with D3. shrug

The added security benefit outweighs this. Someone can "tear down the walls" or add exceptions if desired for their own projects. This processing could happen server-side too, which would be safer.

Overall, I think this is good to go after a few minor fixes I noted in-line. Feel free to make those @mhaddy , and this should be good to merge I think. Thanks!

Renamed function call, removed unused line, and aligned to project code standards.
@mhaddy
Copy link
Contributor Author

mhaddy commented Feb 25, 2018

@nelsonic @mckennapsean Please review the changes - I believe I've addressed all of your feedback.

@mckennapsean
Copy link
Collaborator

Thanks for cleaning that up! Will get it merged soon.

@mckennapsean
Copy link
Collaborator

Done, deployed in production.

@mckennapsean mckennapsean merged commit c61f918 into dwyl:master Mar 4, 2018
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