Allow users to provide their token via a stdin prompt

Currently the only way to provide a token is via the CLI arg --token. This is not ideal because the token will be saved to the shell history, which makes it easier to steal and easier to leak.

Instead this PR provides an implementation where the user can run the command exercism configure without providing a token and then the user will be asked to provide the token via a stdin input.

This token has been reset.


Also thank you for making exercism, it is my go to spot for learning new languages.

1 Like

I have implemented an initial version of this in my PR. I would be happy to hear your comments on it.

read -r token
exercism configure --token "$token"

Works for any tool and any token :wink:

Or you can disable the history file for that shell session. Optionally use a subshell for this.

bash
unset HISTFILE
exercism configure --token not_recorded

Yes you are right. I am not saying there aren’t other ways of securely providing the token.

I just thought i would add support for a more convenient way of doing it, oh well.

1 Like

I would also like to add that if users are expected to know and use these ad hoc methods of securely providing the token, then these methods should be mentioned in the documentation. Otherwise, Exercism would be knowingly instructing users to use an insecure method, which could later expose them (the users) to problems down the road.

I wouldn’t call that insecure. Users typically assume data in their home directory is secure. If that assumption doesn’t hold, you’re in trouble either way. The exercism tool writes the token in plaintext to a JSON file. If you “securely” provide the token and avoid writing it to the shell history file, it is still in the Exercism config file. Not to mention all the browser cookies which can be used to access any websites you’re logged into.

You make some good points. My main concern is the possibility of the token being exposed when a user is navigating their shell history (by repeatedly pressing up, for example). The reason I considered implementing this safeguard is that it happened to me while recording a video demonstrating some OCaml problems. Fortunately, since it was a recording, I was able to edit it out, but this could have been a bigger problem if it had been a live stream.

A clarification, the PR doesn’t remove the functionality of providing the token via the --token flag. The PR only adds an additional way to provide the token if the user runs the configure command without a token flag.

exercsim configure

Hi there. Thanks for this.

I’m tentatively :+1:. But I don’t like that we lose the information that tells the student where to get the token from up front. So I’d like to add that back in.

@ErikSchierboom Thoughts?

Yes you’re right, the student should know where they can get their token.

Does this accomplish that?

This feels slightly weird to me as there are more things that can be configured. Why should it default to the token?

That’s a good point. My plan was to ensure that the token doesn’t get stored in the shell history since it’s sensitive information. The other configuration options don’t appear to be sensitive.

How about specifying --token without a token gives the interactive prompt?

Alternatively, add a new --interactive-token flag? Or a generic --interactive that prompts you for all values (and sets whatever the user enters that is not empty)?

1 Like

I don’t know if this is the right way to go. Using the same flag --token as a value provider and as a conditional value to enable interactivity could complicate the argument parsing logic and it is also a more complicated interface for students.

I think the current implementation of having the bare command (configure with no flags) be a signal to start the interactive input scheme makes more sense.

This could also work.

I like that.

Ok seems like we all agree on using the --interactive flag. I have pushed a new commit to the PR that implements prompting students for their token only when the --interactive flag is set.

I think the above discussion suggested that --interactive should allow all values to be set? (obviously we should keep existing settings if the user just presses enter)

What are the other values a student might want to change, maybe the config directory?

I don’t know what this is in reference to. Is it about the latest commit.

Also, it’s kind of hard to tell what i should change about the current implementation from reading the comments in this discussion, would you mind leaving reviews on the PR so that i know what i should change

@frectonz To me these comments read as: Ongoing discussion. No need to immediately change your code.

I prefer explicitly invoking interactive modes. And printing the help text when no arguments are given. So --interactive would be my choice.

For interactive modes I find preseting the current value of a setting (“if you enter nothing, this value will be taken”) is most useful. This allows skipping values I don’t want to change and interactively enter new values.

2 Likes