We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[CKV_DOCKER_7] Erroneous failed check when --platform flag is used in multistage Dockerfile
**Describe the issue**
In the `CKV_DOCKER_7` check, when the `--platform` flag is used in a multistage Dockerfile, the check fails erroneously for images that have been created within the current Dockerfile and thus no version pegging should be required.

**Examples**
The Dockerfile below is green

```
FROM golang:1.20-bullseye AS base

FROM base AS build
```

but as soon as a `--platform` flag is added, the check fails:

```
FROM --platform=$BUILDPLATFORM golang:1.20-bullseye AS base

FROM base AS build
```

**Version (please complete the following information):**
 - Checkov Version 2.4.4

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `checkov/dockerfile/checks/ReferenceLatestTag.py`
Content:
```
1 from __future__ import annotations
2 
3 import re
4 from typing import TYPE_CHECKING
5 
6 from checkov.common.models.enums import CheckCategories, CheckResult
7 from checkov.dockerfile.base_dockerfile_check import BaseDockerfileCheck
8 
9 if TYPE_CHECKING:
10     from dockerfile_parse.parser import _Instruction
11 
12 MULTI_STAGE_PATTERN = re.compile(r"(\S+)\s+as\s+(\S+)", re.IGNORECASE)
13 
14 
15 class ReferenceLatestTag(BaseDockerfileCheck):
16     def __init__(self) -> None:
17         name = "Ensure the base image uses a non latest version tag"
18         id = "CKV_DOCKER_7"
19         supported_instructions = ("FROM",)
20         categories = (CheckCategories.CONVENTION,)
21         super().__init__(name=name, id=id, categories=categories, supported_instructions=supported_instructions)
22 
23     def scan_resource_conf(self, conf: list[_Instruction]) -> tuple[CheckResult, list[_Instruction] | None]:
24         stages = []
25 
26         for content in conf:
27             base_image = content["value"]
28             if " as " in base_image.lower():
29                 # do an initial lookup before using the regex
30                 multi_stage = re.match(MULTI_STAGE_PATTERN, base_image)
31                 if multi_stage:
32                     base_image = multi_stage[1]
33                     stages.append(multi_stage[2])
34 
35             if ":" not in base_image and base_image not in stages and base_image != "scratch":
36                 return CheckResult.FAILED, [content]
37             elif base_image.endswith(":latest"):
38                 return CheckResult.FAILED, [content]
39         return CheckResult.PASSED, [content]
40 
41 
42 check = ReferenceLatestTag()
43
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/checkov/dockerfile/checks/ReferenceLatestTag.py b/checkov/dockerfile/checks/ReferenceLatestTag.py
--- a/checkov/dockerfile/checks/ReferenceLatestTag.py
+++ b/checkov/dockerfile/checks/ReferenceLatestTag.py
@@ -9,7 +9,7 @@
 if TYPE_CHECKING:
     from dockerfile_parse.parser import _Instruction
 
-MULTI_STAGE_PATTERN = re.compile(r"(\S+)\s+as\s+(\S+)", re.IGNORECASE)
+MULTI_STAGE_PATTERN = re.compile(r"(?:--platform=\S+\s+)?(\S+)\s+as\s+(\S+)", re.IGNORECASE)
 
 
 class ReferenceLatestTag(BaseDockerfileCheck):

{"golden_diff": "diff --git a/checkov/dockerfile/checks/ReferenceLatestTag.py b/checkov/dockerfile/checks/ReferenceLatestTag.py\n--- a/checkov/dockerfile/checks/ReferenceLatestTag.py\n+++ b/checkov/dockerfile/checks/ReferenceLatestTag.py\n@@ -9,7 +9,7 @@\n if TYPE_CHECKING:\n     from dockerfile_parse.parser import _Instruction\n \n-MULTI_STAGE_PATTERN = re.compile(r\"(\\S+)\\s+as\\s+(\\S+)\", re.IGNORECASE)\n+MULTI_STAGE_PATTERN = re.compile(r\"(?:--platform=\\S+\\s+)?(\\S+)\\s+as\\s+(\\S+)\", re.IGNORECASE)\n \n \n class ReferenceLatestTag(BaseDockerfileCheck):\n", "issue": "[CKV_DOCKER_7] Erroneous failed check when --platform flag is used in multistage Dockerfile\n**Describe the issue**\r\nIn the `CKV_DOCKER_7` check, when the `--platform` flag is used in a multistage Dockerfile, the check fails erroneously for images that have been created within the current Dockerfile and thus no version pegging should be required.\r\n\r\n**Examples**\r\nThe Dockerfile below is green\r\n\r\n```\r\nFROM golang:1.20-bullseye AS base\r\n\r\nFROM base AS build\r\n```\r\n\r\nbut as soon as a `--platform` flag is added, the check fails:\r\n\r\n```\r\nFROM --platform=$BUILDPLATFORM golang:1.20-bullseye AS base\r\n\r\nFROM base AS build\r\n```\r\n\r\n**Version (please complete the following information):**\r\n - Checkov Version 2.4.4\n", "before_files": [{"content": "from __future__ import annotations\n\nimport re\nfrom typing import TYPE_CHECKING\n\nfrom checkov.common.models.enums import CheckCategories, CheckResult\nfrom checkov.dockerfile.base_dockerfile_check import BaseDockerfileCheck\n\nif TYPE_CHECKING:\n    from dockerfile_parse.parser import _Instruction\n\nMULTI_STAGE_PATTERN = re.compile(r\"(\\S+)\\s+as\\s+(\\S+)\", re.IGNORECASE)\n\n\nclass ReferenceLatestTag(BaseDockerfileCheck):\n    def __init__(self) -> None:\n        name = \"Ensure the base image uses a non latest version tag\"\n        id = \"CKV_DOCKER_7\"\n        supported_instructions = (\"FROM\",)\n        categories = (CheckCategories.CONVENTION,)\n        super().__init__(name=name, id=id, categories=categories, supported_instructions=supported_instructions)\n\n    def scan_resource_conf(self, conf: list[_Instruction]) -> tuple[CheckResult, list[_Instruction] | None]:\n        stages = []\n\n        for content in conf:\n            base_image = content[\"value\"]\n            if \" as \" in base_image.lower():\n                # do an initial lookup before using the regex\n                multi_stage = re.match(MULTI_STAGE_PATTERN, base_image)\n                if multi_stage:\n                    base_image = multi_stage[1]\n                    stages.append(multi_stage[2])\n\n            if \":\" not in base_image and base_image not in stages and base_image != \"scratch\":\n                return CheckResult.FAILED, [content]\n            elif base_image.endswith(\":latest\"):\n                return CheckResult.FAILED, [content]\n        return CheckResult.PASSED, [content]\n\n\ncheck = ReferenceLatestTag()\n", "path": "checkov/dockerfile/checks/ReferenceLatestTag.py"}], "after_files": [{"content": "from __future__ import annotations\n\nimport re\nfrom typing import TYPE_CHECKING\n\nfrom checkov.common.models.enums import CheckCategories, CheckResult\nfrom checkov.dockerfile.base_dockerfile_check import BaseDockerfileCheck\n\nif TYPE_CHECKING:\n    from dockerfile_parse.parser import _Instruction\n\nMULTI_STAGE_PATTERN = re.compile(r\"(?:--platform=\\S+\\s+)?(\\S+)\\s+as\\s+(\\S+)\", re.IGNORECASE)\n\n\nclass ReferenceLatestTag(BaseDockerfileCheck):\n    def __init__(self) -> None:\n        name = \"Ensure the base image uses a non latest version tag\"\n        id = \"CKV_DOCKER_7\"\n        supported_instructions = (\"FROM\",)\n        categories = (CheckCategories.CONVENTION,)\n        super().__init__(name=name, id=id, categories=categories, supported_instructions=supported_instructions)\n\n    def scan_resource_conf(self, conf: list[_Instruction]) -> tuple[CheckResult, list[_Instruction] | None]:\n        stages = []\n\n        for content in conf:\n            base_image = content[\"value\"]\n            if \" as \" in base_image.lower():\n                # do an initial lookup before using the regex\n                multi_stage = re.match(MULTI_STAGE_PATTERN, base_image)\n                if multi_stage:\n                    base_image = multi_stage[1]\n                    stages.append(multi_stage[2])\n\n            if \":\" not in base_image and base_image not in stages and base_image != \"scratch\":\n                return CheckResult.FAILED, [content]\n            elif base_image.endswith(\":latest\"):\n                return CheckResult.FAILED, [content]\n        return CheckResult.PASSED, [content]\n\n\ncheck = ReferenceLatestTag()\n", "path": "checkov/dockerfile/checks/ReferenceLatestTag.py"}]}