Skip to content

Commit 442e872

Browse files
authored
Mask api key in command logging (#1580)
* Mask api key in command logging * Bump changelog
1 parent aca68a9 commit 442e872

2 files changed

Lines changed: 26 additions & 8 deletions

File tree

Changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# FOSSA CLI Changelog
22

3+
## 3.11.4
4+
5+
- Stops logging a secret under `--x-snippet-scan`. ([#1579](https://github.com/fossas/fossa-cli/pull/1580))
6+
37
## 3.11.3
48

59
- Picks up the latest version of a dependency for `--x-snippet-scan`. ([#1579](https://github.com/fossas/fossa-cli/pull/1579))

src/App/Fossa/Ficus/Analyze.hs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ runFicus ficusConfig = do
151151
logDebugWithTime "Ficus binary extracted, building command..."
152152
cmd <- ficusCommand ficusConfig bin
153153
logDebugWithTime "Executing ficus (streaming)"
154-
logDebug $ "Ficus command: " <> pretty (renderCommand cmd)
155154
logDebug $ "Working directory: " <> pretty (toFilePath $ ficusConfigRootDir ficusConfig)
156155

157156
logDebugWithTime "Creating process configuration..."
@@ -235,26 +234,41 @@ runFicus ficusConfig = do
235234

236235
-- Run Ficus, passing config-based args as configuration.
237236
-- Caveat! This hard-codes some flags currently which may later need to be set on a strategy-by-strategy basis.
238-
ficusCommand :: Has Diagnostics sig m => FicusConfig -> BinaryPaths -> m Command
237+
ficusCommand :: (Has Diagnostics sig m, Has Logger sig m) => FicusConfig -> BinaryPaths -> m Command
239238
ficusCommand ficusConfig bin = do
240239
endpoint <- case ficusConfigEndpoint ficusConfig of
241240
Just baseUri -> do
242241
proxyUri <- setPath [PathComponent "api", PathComponent "proxy", PathComponent "analysis"] (TrailingSlash False) baseUri
243242
pure $ render proxyUri
244243
Nothing -> pure "https://app.fossa.com/api/proxy/analysis"
245-
pure $
246-
Command
247-
{ cmdName = toText $ toPath bin
248-
, cmdArgs = configArgs endpoint
249-
, cmdAllowErr = Never
250-
}
244+
let cmd =
245+
Command
246+
{ cmdName = toText $ toPath bin
247+
, cmdArgs = configArgs endpoint
248+
, cmdAllowErr = Never
249+
}
250+
logDebug $ "Ficus command: " <> pretty (maskApiKeyInCommand $ renderCommand cmd)
251+
pure cmd
251252
where
252253
configArgs endpoint = ["analyze", "--secret", secret, "--endpoint", endpoint, "--locator", locator, "--set", "all:skip-hidden-files", "--set", "all:gitignore", "--exclude", ".git", "--exclude", ".git/**"] ++ configExcludes ++ [targetDir]
253254
targetDir = toText $ toFilePath $ ficusConfigRootDir ficusConfig
254255
secret = maybe "" (toText . unApiKey) $ ficusConfigSecret ficusConfig
255256
locator = renderLocator $ Locator "custom" (projectName $ ficusConfigRevision ficusConfig) (Just $ projectRevision $ ficusConfigRevision ficusConfig)
256257
configExcludes = unGlobFilter <$> ficusConfigExclude ficusConfig
257258

259+
maskApiKeyInCommand :: Text -> Text
260+
maskApiKeyInCommand cmdText =
261+
case Text.splitOn " --secret " cmdText of
262+
[before, after] ->
263+
case Text.words after of
264+
(_ : rest) ->
265+
before
266+
<> " --secret "
267+
<> "******"
268+
<> if null rest then "" else " " <> Text.unwords rest
269+
[] -> cmdText
270+
_ -> cmdText
271+
258272
-- add a FicusMessage to the corresponding entry of an empty FicusMessages
259273
singletonFicusMessage :: FicusMessage -> FicusMessages
260274
singletonFicusMessage message = case message of

0 commit comments

Comments
 (0)