LoginSignup
15
11

More than 5 years have passed since last update.

PMDとVisual Studio CodeによってSalesforceのソースコードのセキュリティスキャンの自動化

Last updated at Posted at 2018-11-05

「ApexとVisualForceにセキュリティ問題がないか?」と一度悩んだ方が少なくありません。この記事でオープンソースの脆弱性検知ツールを紹介したいと思います。

以下のマニュアルはmacOSとHomebrew用

pmd、 java8とVisual Studio Codeのインストール

$ brew install pmd
$ brew tap caskroom/versions
$ brew cask install java8 
$ brew cask install visual-studio-code

Visual Studio CodeのSalesforce拡張のインストール

$ code --install-extension salesforce.salesforcedx-vscode

Salesforce拡張の設定

Salesforceの拡張はjava8に依存するから、java8のパスを設定する。
⌘ ,を押すかCode→Preferences→Settingsからアクセスし、ユーザー設定を開く。
Screen Shot 2018-10-31 at 16.58.18.png

検索フィールドにsalesforcedx-vscode-apex.java.homeを入力する。Edit in settings.jsonを押す。
Screen Shot 2018-10-31 at 17.02.56.png

$ /usr/libexec/java_home -v 1.8を実行し、java8のパスを調べる。settings.jsonにjava8のパスを以下のように設定する。

{
    "salesforcedx-vscode-apex.java.home": "/Library/Java/JavaVirtualMachines/jdk1.8.0_192.jdk/Contents/Home"
}

Screen Shot 2018-10-31 at 17.12.59.png

PMD taskの設定

Terminal→Configure Tasks...を選択し、Create tasks.json from templateを選んでOthersを押す。
Configure task

以下のコンテンツをコピーペーする。

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "PMD",
            "type": "shell",
            "command": "pmd",
            "args": ["pmd", "-d", "${workspaceFolder}", "-f", "text", "-rulesets", "apex-security,vf-security", "-failOnViolation", "false"],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": {
                "owner": "apex",
                "fileLocation": ["absolute"],
                "pattern": {
                    "regexp": "^([^:]+):([0-9]+):\\s+(.+)$",
                    "file": 1,
                    "line": 2,
                    "message": 3
                }
            }
        }
    ]
}

PMDの実行

Visual Studio Codeで⇧⌘Bのショートカットを利用し、問題を検知する。すべての問題を表示するために⇧⌘Mのショートカットを使う。

Run pmd

15
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
11