import java.io.IOException;
 import java.nio.file.Path;
-import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Enumeration;
 
     private PolicyDecoderFileInCsarToPolicyParameterGroup decoderParameters;
     private StandardCoder coder;
+    private static final long MAX_FILE_SIZE = 512 * 1024;
 
     /**
      * {@inheritDoc}.
         try (ZipFile zipFile = new ZipFile(csar.getCsarPath())) {
             final Enumeration<? extends ZipEntry> entries = zipFile.entries();
             while (entries.hasMoreElements()) {
-                final ZipEntry entry = entries.nextElement();
-                if (isZipEntryValid(entry, csar.getCsarPath())) {
+                //
+                // Sonar will flag this as a Security Hotspot
+                // "Expanding archive files is security-sensitive"
+                // isZipEntryValid ensures the file being read exists in the archive
+                //
+                final ZipEntry entry = entries.nextElement(); // NOSONAR
+                if (isZipEntryValid(entry.getName(), csar.getCsarPath(), entry.getSize())) {
                     final ToscaServiceTemplate policy =
                             coder.decode(zipFile.getInputStream(entry), ToscaServiceTemplate.class);
                     policyList.add(policy);
      * @param entry the ZipEntry to check
      * @param csarPath Absolute path to the csar the ZipEntry is in
      * @return true if no injection detected, and it is a policy type  or policy file.
+     * @throws PolicyDecodingException if the file size is too large
      */
-    private boolean isZipEntryValid(ZipEntry entry, String csarPath) {
+    private boolean isZipEntryValid(String entryName, String csarPath, long entrySize) throws PolicyDecodingException {
         //
         // We only care about policy types and policies
         //
-        if (entry.getName().contains(decoderParameters.getPolicyTypeFileName())
-                || entry.getName().contains(decoderParameters.getPolicyFileName())) {
+        if (entryName.contains(decoderParameters.getPolicyTypeFileName())
+                || entryName.contains(decoderParameters.getPolicyFileName())) {
+            //
+            // Check file size
+            //
+            if (entrySize > MAX_FILE_SIZE) {
+                throw new PolicyDecodingException("Zip entry for " + entryName + " is too large " + entrySize);
+            }
             //
             // Now ensure that there is no path injection
             //
-            Path path = Path.of(csarPath, entry.getName()).normalize();
-            return path.startsWith(csarPath);
+            Path path = Path.of(csarPath, entryName).normalize();
+            //
+            // Throw an exception if path is outside the csar
+            //
+            if (! path.startsWith(csarPath)) {
+                throw new PolicyDecodingException("Potential path injection for zip entry " + entryName);
+            }
+            return true;
         }
 
         return false;