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

stop parsing YAML headers as ERB #31362

Merged
merged 4 commits into from Oct 22, 2019
Merged

stop parsing YAML headers as ERB #31362

merged 4 commits into from Oct 22, 2019

Conversation

Hamms
Copy link
Contributor

@Hamms Hamms commented Oct 18, 2019

Description

Previously, all the YAML headers that we allow in all our pegasus documents could be treated as ERB. This not only led to some very messy scenarios (like this HAML template containing a YAML header containing an ERB expression), but also began to present a security risk once we started to allow translators to translate full files.

The fix is to simply parse YAML only as YAML and not as both YAML and ERB. Any functionality that formerly lived as ruby code in the headers can instead live as ruby code in the ERB and HAML templates themselves for those filetypes; filetypes that do not themselves allow for execution of ruby code will no longer be able to support the old functionality.

Links

Testing story

I added a test to ensure that we don't in the future revert back to the old functionality and explaining our reasoning. I'm also counting on our various "render every document in Pegasus and verify that none of them break" tests.

Reviewer Checklist:

  • Tests provide adequate coverage
  • Code is well-commented
  • New features are translatable or updates will not break translations
  • Relevant documentation has been added or updated
  • User impact is well-understood and desirable
  • Pull Request is labeled appropriately
  • Follow-up work items (including potential tech debt) are tracked and linked

theme: with_title
---

# Hello
Copy link
Member

Choose a reason for hiding this comment

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

Maybe worth a comment mentioning that this is used in a test, and which test that is?

# once we started allowing translators to translate entire files.
#
# This tests exists just to enforce that we don't revert back to the old
# functionality.
Copy link
Member

Choose a reason for hiding this comment

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

Great commenting.

@Hamms Hamms merged commit 443184b into staging Oct 22, 2019
@Hamms Hamms deleted the stop-parsing-yaml-as-erb branch October 22, 2019 21:47
Hamms added a commit that referenced this pull request Oct 23, 2019
As it turns out, emails don't use the rendering logic I updated in #31362 and so don't need to stop using ERB in their YAML header just yet; they use https://github.com/code-dot-org/code-dot-org/blob/staging/lib/cdo/pegasus/text_render.rb, specifically https://github.com/code-dot-org/code-dot-org/blob/8bfb480e91fec4a6e39d3727634d26f85b73f4df/lib/cdo/pegasus/text_render.rb#L190-L205 which still supports ERB (see https://github.com/code-dot-org/code-dot-org/blob/8bfb480e91fec4a6e39d3727634d26f85b73f4df/bin/cron/deliver_poste_messages#L63-L74 for more details).

In addition, they actually only define @Header if one is detected, so the change to assign metadata directly to that variable was failing because it never got initialized. Reverting these templates to their old format fixes things for now, and I'll track longer-term work to update YamlEngine
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.

None yet

2 participants