A shutoff valve is a control device that blocks oil flow in a pipeline in order to reduce the oil escape. This paper addresses the valve location problem where, given a pipeline network and a number of valves for installation, the task is to find a valve location that minimizes the maximum environmental damage of an oil spill. We present the first complete framework for fast computing of an optimal valve location in a general oil pipeline network. To achieve this, we formalize the problem and explain how to quantify environmental damages. Next, we present two fast algorithms optimally solving the valve location problem on linear pipeline segments. Further, we show how to extend the algorithms to solve the problem on a general pipeline network. We conclude with a computational study showing that solutions provided by our framework can reduce the adverse effects of a spill by up to 37% compared to the currently used solutions.