Skip to content

Make executable links safer #11273

Closed
Closed

Description

@hadley

The current behaviour of code-executing hyperlinks feels a bit risky — obviously we'll be careful with our use of it, but we have introduced a fairly easy way to introduce easily executable code into the output. I think it would be nice if clicking on the link showed a popup with exactly what code would be run along with a button that would run it.

Activity

  1. romainfrancois commented on May 24, 2022

    @romainfrancois
    Contributor

    Relatedly, should they be styled slightly differently ? because the action is different: do something rather than go somewhere ? Maybe they can look more like a button ?

  2. romainfrancois commented on May 24, 2022

    @romainfrancois
    Contributor

    Would "copy the code in the console" without running it be enough ? Then the user would have to hit enter and so can check the code.

  3. hadley commented on May 24, 2022

    @hadley
    MemberAuthor

    I think we still want some way to run the code just by using the mouse

  4. mikebessuille commented on May 24, 2022

    @mikebessuille
    Contributor

    @kevinushey @romainfrancois @jgutman Are these links actually running code? I thought they would just take you to a location in the current file, or to an external link.

  5. kevinushey commented on May 24, 2022

    @kevinushey
    Collaborator

    @kevinushey @romainfrancois @jgutman Are these links actually running code? I thought they would just take you to a location in the current file, or to an external link.

    They do so by running code in the R session (we have an RPC so that the R session can handle the navigation attempt).

    That said, as I understand it, RStudio just understands how to follow file URIs with some extra metadata, and all of that processing goes through .rs.rpc.console_follow_hyperlink(). In other words, we're not just evaluating arbitrary user input within a hyperlink; we're handling a semi-internal protocol for generated links. Is that correct, or am I missing something separate?

    Relatedly, should they be styled slightly differently ? because the action is different: do something rather than go somewhere ? Maybe they can look more like a button ?

    For what it's worth, I like the current treatment.

  6. 45 remaining items

  7. romainfrancois commented on Jun 15, 2022

    @romainfrancois
    Contributor

    final QA note: there were a lot of discussion here. Here are some final code to test this:

    # original issue: https://github.com/rstudio/rstudio/issues/1941
    # last pull request: https://github.com/rstudio/rstudio/pull/11421
    
    # web page ----------------------------------------------------------------
    # clicking should open the webpage
    cli::style_hyperlink("rstudio", "https://www.rstudio.com")
    
    # File --------------------------------------------------------------
    # clicking should open the file ... 
    file <- tempfile(fileext = ".R")
    writeLines("hello\nhola\nbonjour", file)
    # ... at the beginning
    cli::style_hyperlink("file", paste0("file://", file))
    # ... at line 2, column 2
    cli::style_hyperlink("file", paste0("file://", file), c(line = 2, col = 2))
    
    # Help --------------------------------------------------------------------
    # hovering will show preview information about dplyr::summarise
    # clicking will open the full help page in the help pane
    cli::style_hyperlink("help page", "ide:help:dplyr::summarise")
    # same
    cli::style_hyperlink("help page", "ide:help", c(topic = "summarise", package = "dplyr"))
    # popup says "package not found"
    # clicking errors with:
    #   Error in find.package(if (is.null(package)) loadedNamespaces() else package,  : 
    #   there is no package called ‘dply’
    cli::style_hyperlink("help page", "ide:help:dply::summarise")
    # hovering says "documentation not found"
    # clicking errors with: 
    #    No documentation for ‘zummarise’ in specified packages and libraries:
    #    you could try ‘??zummarise’
    cli::style_hyperlink("help page", "ide:help:dplyr::zummarise")
    
    # Vignette ----------------------------------------------------------------
    # popup shows title and description for the vignette
    # clicking opens the vignette in the help pane
    cli::style_hyperlink("vignette", "ide:vignette:dplyr::dplyr")
    # package not found
    cli::style_hyperlink("vignette", "ide:vignette:dply::dplyr")
    # vignette not found
    cli::style_hyperlink("vignette", "ide:vignette:dplyr::dply")
    
    # Code --------------------------------------------------------------
    
    # popup shows help for rlang::last_error
    # clicknig runs the code
    cli::style_hyperlink("show traceback", "ide:run:rlang::last_error()")
    
    # if sessioninfo is installed, the popup will show some information
    # clicking will just copy the code in the console
    cli::style_hyperlink("show session info", "ide:run:sessioninfo::session_info()")
    
    # foo is not installed, code also just copied
    cli::style_hyperlink("show foo", "ide:run:foo::bar()")
    
    # forbidden, clicking does nothing
    cli::style_hyperlink("show traceback ...", "ide:run:rm(list = ls())")
    cli::style_hyperlink("show traceback ...", "ide:run:base::rm(list = ls())")
    cli::style_hyperlink("show traceback ...", "ide:run:base::source('http://example.org/code.R')")
    cli::style_hyperlink("show traceback ...", "ide:run:base::system('rm -fr /')")
    
    cli::style_hyperlink("show traceback ...", "ide:run:rlang::last_error(); rm(list = ls())")
    cli::style_hyperlink("show traceback ...", "ide:run:rlang::last_error(a = rm(list = ls()))")
  8. assigned and unassigned on Jun 15, 2022
  9. ronblum commented on Jun 15, 2022

    @ronblum
    Contributor

    Verified in

    • RStudio Desktop 2022.06.0-daily+528 on MacOS 12.5
    • RStudio Server 2022.06.0-daily+528 on Ubuntu 20.04 via Chrome and Firefox

    Leaving this open as a candidate for automated testing.

  10. ronblum commented on Jun 15, 2022

    @ronblum
    Contributor

    Closing as complete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions