In my case, the static code analysis tool shows the issue when it founds the code like this:

boolean status = file.delete(); 

It issues the security vulnerability saying the validation is required.

On further investigation, I found that Java's file manipulation methods on failure returns a value instead of throwing an exception.

Reference: FIO02-J. Detect and handle file-related errors.

But no detailed explanation found considering security
Could any one please explain what security risk is with the File delete method?

1 Answer 1


A failed deletion is a security risk only if all of the following hold:

  • the target file does exist;
  • that file contains sensitive data;
  • the deletion fails for "some reason";
  • in the assumed attack model, the attacker can at some point access the contents of the file that was deleted, but, for some reason, would not have been able to access these contents if the file was deleted.

(The fourth condition is about an often overlooked feature of file deletion: it does not really delete the data, it just marks the corresponding slots in the physical medium as free to reuse, but the data itself may still linger for unbounded amounts of time.)

Even when there is such a risk, then there is very little that you can do. The deletion failed, so chances are that it will keep on failing; throwing an exception would, at best, prevent the deletion failure from occurring silently. Note that throwing an exception or raising some sort of alert could also help attacks, depending on the context: leaking confidential data is a security issue; killing running applications is also a security issue (if it can be forced from the outside).

It would be wrong to flag any unchecked deletion as "a security issue". At best, it could be flagged as "a bug that might be a security issue (just like any other bug), depending on conditions".

  • Thanks for the information Thomas. In my case the scenario is like Define File object, do some zip operations then the deletion operation is performed. In this case, is still is it vulnerable as the existence of file may cause issue while performing zip operations itself or the lack of authorization resulting into SecurityException. Thanks, Guru
    – guru
    Nov 6, 2014 at 9:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .