Elegant system calls in haskell

I am creating a website where users can log in using the kerberos service. Although, this is completely irrelevant to my problem.

Since I use kerberos, I want to use the system call to call kinit , but I don't know how to do this.

So far I have received:

 module Kerberos where system :: String -> IO ExitCode -- system is loaded through imports type Username = String type Password = String kerberosValidate :: Username -> Password -> IO Bool kerberosValidate username password = fmap (== ExitSuccess) $ system $ "echo " ++ password ++ " | kinit " ++ username 

Something like this that should work so-so. I have three problems with this though.

  • Unable to escape username and password strings. This is important because the website passes any input received to this function.
  • Ideally, password should not be passed to the kinit process using echo password | . Is there any function that takes a standard as an argument?
  • Similarly for username , username should be passed as an argument. I think rawSystem solves this though.

Is there some kind of system function that helps me here?

+6
source share
1 answer

Use createProcess and friends from System.Process .


Security Note: I would advise against passing any lines through uninterpreted. You can easily write a parser for your teams, build a Haskell AST from an analysis result that is guaranteed to be safe, and then display it to the system command. Thus, you will receive a static guarantee against attacks on inserting strings that will be executed as an analyzer.

+6
source

Source: https://habr.com/ru/post/890350/


All Articles