Skip to content

Allow command: links in hover decorations #29076

Closed

Description

@eamodio
  • VSCode Version: Code - Insiders 1.14.0-insider (77bf512, 2017-06-19T08:59:44.265Z)
  • OS Version: Windows_NT ia32 10.0.16215

It would be great to be able to execute commands from hover decorations. It would provide for powerful navigation options as well as open up many other uses.

For example, in GitLens I would love to have the shas eb411003 & 078960e8 be links that would open the commit details command. And the Changes be a link to open the diff with previous command.

Activity

  1. eamodio commented on Jun 20, 2017

    @eamodio
    ContributorAuthor

    Matt Bierner (@mjbvz) I should have dug deeper, but it looks like this changed very recently here: fe8ea99

  2. mjbvz commented on Jun 20, 2017

    @mjbvz
    Contributor

    Eric Amodio (@eamodio) Yes there's a bit of history to that change. In summary: command: uris are a security concern and they were previously enabled in many more places than they should have been, including in hovers. The concern is that commands have not been validated for safety which may allow an evildoer to craft some evil source code that could trick a user into executing a vscode command:

    /**
     * Does stuff
     *
     * [Learn More](command:runShellComamnd?rm%20-rf%20%25)
     */
    export function doStuff() { ... }

    fe8ea99 attempted to fix this

    I don't know if there is a safe way to selectively re-enable this functionality. Let me know if you have any thoughts on this

  3. eamodio commented on Jun 20, 2017

    @eamodio
    ContributorAuthor

    Ah - I see. Could maybe the extension provide a whitelist of commands that should be allowed in a hover? Because having commands in hovers can be quite powerful, and I'd hate to completely lose that ability (even though I didn't think it worked because I was always trying to wrap a link around a code block which caused the action to never trigger).

    Or maybe have an command callback on a hover that would allow an extension to see the command being attempted and take its own action? That might be nicer than a whitelist -- but it could be abused if an extension was lazy and just blindly forwarded commands.

  4. mjbvz commented on Jun 21, 2017

    @mjbvz
    Contributor

    Johannes Rieken (@jrieken) Any thoughts on supporting some form of interactivity in hovers? I'm inclined to keep hovers limited to static content.

    If we did want to support actions in the hover, the HoverProvider may be a good place to handle these.

  5. eamodio commented on Jun 21, 2017

    @eamodio
    ContributorAuthor

    I would argue that there was (and still is) interactivity in hovers -- you have just taken away a part of it (for perfectly reasonable security concerns). But I would hope that the feature that used to work (which could have the security concerns mitigated) would not be lost altogether -- just changed for security.

    As for hover decorations vs hover providers -- again I would argue that this feature has already existed and will continue to exist for both external links as well as internal file links.

    Also, I want to point out that not only have command links been lost, but also custom TextDocumentContentProvider links -- are those also of the same security risk?

  6. jrieken commented on Jun 21, 2017

    @jrieken
    Contributor

    Johannes Rieken (@jrieken) Any thoughts on supporting some form of interactivity in hovers? I'm inclined to keep hovers limited to static content.

    Yeah, I think is critical that we are taking features aways. This has been working and advertised since at least a year. Why don't we do something similar to script execution and the preview command? There we didn't just disable script execution but prompted the user in some way. I think taking the big hammer to solve this problem won't make people happy.

  7. mjbvz commented on Jun 21, 2017

    @mjbvz
    Contributor

    I only recall seeing command uris documented for html previews. That they worked in hovers seemed like a side effect of using the OpenerService to handle links. Was this really a feature that we officially supported?

    In the markdown preview, we disabled scripts by default and then provided a setting to enable them again. Prompting works fine for the markdown preview because the markdown content comes from the user. For UX, I'm not in favor of a prompt based solution here because the content is coming from an extension which the user has already trusted. How should they know which commands to trust and which not to? A whitelist of valid commands for given hover would be better.

    Unless a large number of users will be negatively impacted when some existing extensions stop working, we need to ship 1.14 with the current change that uses a whitelist of valid link schemes, or at the very least entirely disable command uris in hovers. If we ever do want to interactive functionality in hovers, we should look into a proper solution that does not use marked strings and command uris

  8. jrieken commented on Jun 21, 2017

    @jrieken
    Contributor

    I didn't say prompt allow user in some way to keep/restore the old behaviour. Generally, the dislike is expressed when things are taken away. How about making it a user-setting? I don't think that whitelisting necessary works because my good and proper extension might be (ab)used by a third party to with special crafted contents. So, I'd its a generic, single trust switch which defaults to "safe"

  9. eamodio commented on Jun 21, 2017

    @eamodio
    ContributorAuthor

    Depending on how "safe" things need to be having something like a onDidExecuteCommand on the decorator feels somewhat natural to the api -- similar in spirit to onDidSelectItem in the QuickPicks. As I mentioned above, the main downside I see is that an extension could be lazy and just forward on commands without inspecting -- re-opening the security hole. But is that a legitimate concern? Extensions could do all sorts of "bad" things.

    Where as if we are worried about that security risk, having something like hoverMessageCommands?: string[] (don't love the name) whitelist on a decorator feels like a reasonable compromise -- it is explicit, it only affect extensions that really want this behavior, and it should be fairly safe. It also doesn't feel like a big ask for an extension to provide with the hover the set of commands it expects in a given hover. The biggest downside I see is it is somewhat different than other areas of the api.

    As for a single trust switch -- I'm not sure I understand what that means -- would it be per extensions? Would it be on the first executing of a specific command? Would there be a blacklist of commands that would be considered "unsafe" (blacklists are of course problematic)?

  10. jrieken commented on Jun 21, 2017

    @jrieken
    Contributor

    Extensions could do all sorts of "bad" things.

    That is correct and there is little we can do. However, there is a scenario in which a good extension can be made do evil thing by special input, e.g. a source file which results in a special hover command. Because of that a list of approached commands won't help much and I'd opt for a global flag (user-setting) that says "I understand and I am OK with the risk"

  11. 81 remaining items

  12. eamodio commented on Aug 28, 2017

    @eamodio
    ContributorAuthor

    Johannes Rieken (@jrieken) will the api be in August but not enforced until Sept or no api until Sept too?

  13. jrieken commented on Aug 28, 2017

    @jrieken
    Contributor

    Yes, the new MarkdownString will ship for August (it already is in insiders) and the default behaviour for MarkedString will change in September.

  14. eamodio commented on Aug 28, 2017

    @eamodio
    ContributorAuthor

    Awesome -- thank you. New GitLens features coming ;)

  15. jrieken commented on Sep 7, 2017

    @jrieken
    Contributor

    Closing this as the new API is out and adopting is being tracked here: #33577

  16. added
    verification-needed
    on Sep 25, 2017
  17. roblourens commented on Sep 26, 2017

    @roblourens
    Member

    Can you clarify what the change was for september, and what part of it needs to be verified for this issue?

  18. eamodio commented on Sep 27, 2017

    @eamodio
    ContributorAuthor

    Not sure if Johannes Rieken (@jrieken) wanted something specific checked, but this works for me in GitLens now:
    image

    Those links are all command links now

  19. added
    verified
    on Sep 27, 2017
  20. locked and limited conversation to collaborators on Nov 17, 2017
  21. added a commit that references this issue on Sep 6, 2026
    7baa998
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

apieditor-contribfeature-requestrelease-notesverification-neededverified

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions