Skip to content

Script elements in template files should be innert #2766

Closed

Description

@IgorMinar

Given a template:

    some component template containing script tag
    <script>
      console.log('dfsdf');
      alert("hello");
   </script>

associated with a component:

@Component({
  selector: 'test-component'
})
@View({
  template: 'test-component.html'
})
...

when the component is instantiated the script executes.

The root cause of this issue appears to be that we use document.importNode(node, true) when importing contents from the template into the main document. During this import the script element is revived and once appended to the document it's executed.

In Angular component templates this behavior is undesirable since the script is very limited in what it can do (it has no access to the context, di, etc) and only exposes large security vulnerability surface.

Tested with alpha-28.

Activity

  1. added this to the alpha-30 milestone on Jun 29, 2015
  2. changed the title [-]Template files should be innert[/-] [+]Script elements in template files should be innert[/+] on Jun 29, 2015
  3. modified the milestone: alpha-30 on Jul 1, 2015
  4. modified the milestone: alpha-31 on Jul 1, 2015
  5. modified the milestones: alpha-31, alpha-33 on Jul 11, 2015
  6. 4 remaining items

  7. tbosch commented on Jul 30, 2015

    @tbosch
    Contributor

    Related, as it allows to clone templates via element.innerHTML which does not trigger script elements: #3364

  8. mhevery commented on Aug 4, 2015

    @mhevery
    Contributor

    I think we should just remove <script> tags in compilation. (Optionally move them into HEAD if that is want.)

  9. pkozlowski-opensource commented on Aug 5, 2015

    @pkozlowski-opensource
    Member

    I would vote for removing those tags altogether as I don't think we want to act as a "poor's man" loader via templates. Will send a first-shot PR so we can discuss.

  10. added a commit that references this issue on Aug 5, 2015
    a9dc98d
  11. mhevery commented on Aug 6, 2015

    @mhevery
    Contributor
  12. added a commit that references this issue on Aug 15, 2015
    3b50089
  13. IgorMinar commented on Jun 29, 2016

    @IgorMinar
    ContributorAuthor

    @ianbelcher can you please open a new issue requesting JSON-LD support and reference this issue there? thank you!

  14. angular-automatic-lock-bot commented on Sep 8, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  15. locked and limited conversation to collaborators on Sep 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions