Changeset 11526 in josm


Ignore:
Timestamp:
2017-02-02T01:22:52+01:00 (7 years ago)
Author:
Don-vip
Message:

fix #14319 - CVE-2017-5617: svgSalamander SSRF (Server-Side Request Forgery)

Location:
trunk
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/com/kitfox/svg/ImageSVG.java

    r11525 r11526  
    115115            {
    116116                URI src = sty.getURIValue(getXMLBase());
     117                // CVE-2017-5617: Allow only data scheme
    117118                if ("data".equals(src.getScheme()))
    118119                {
    119120                    imageSrc = new URL(null, src.toASCIIString(), new Handler());
    120                 } else
    121                 {
    122                     try
    123                     {
    124                         imageSrc = src.toURL();
    125                     } catch (Exception e)
    126                     {
    127                         Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
    128                             "Could not parse xlink:href " + src, e);
    129 //                        e.printStackTrace();
    130                         imageSrc = null;
    131                     }
    132121                }
    133122            }
     
    137126        }
    138127
    139         diagram.getUniverse().registerImage(imageSrc);
    140 
    141         //Set widths if not set
    142         BufferedImage img = diagram.getUniverse().getImage(imageSrc);
    143         if (img == null)
    144         {
     128        if (imageSrc != null)
     129        {
     130            diagram.getUniverse().registerImage(imageSrc);
     131
     132            //Set widths if not set
     133            BufferedImage img = diagram.getUniverse().getImage(imageSrc);
     134            if (img == null)
     135            {
     136                xform = new AffineTransform();
     137                bounds = new Rectangle2D.Float();
     138                return;
     139            }
     140
     141            if (width == 0)
     142            {
     143                width = img.getWidth();
     144            }
     145            if (height == 0)
     146            {
     147                height = img.getHeight();
     148            }
     149
     150            //Determine image xform
    145151            xform = new AffineTransform();
    146             bounds = new Rectangle2D.Float();
    147             return;
    148         }
    149 
    150         if (width == 0)
    151         {
    152             width = img.getWidth();
    153         }
    154         if (height == 0)
    155         {
    156             height = img.getHeight();
    157         }
    158 
    159         //Determine image xform
    160         xform = new AffineTransform();
    161 //        xform.setToScale(this.width / img.getWidth(), this.height / img.getHeight());
    162 //        xform.translate(this.x, this.y);
    163         xform.translate(this.x, this.y);
    164         xform.scale(this.width / img.getWidth(), this.height / img.getHeight());
     152            xform.translate(this.x, this.y);
     153            xform.scale(this.width / img.getWidth(), this.height / img.getHeight());
     154        }
    165155
    166156        bounds = new Rectangle2D.Float(this.x, this.y, this.width, this.height);
     
    336326                URI src = sty.getURIValue(getXMLBase());
    337327
    338                 URL newVal;
     328                URL newVal = null;
     329                // CVE-2017-5617: Allow only data scheme
    339330                if ("data".equals(src.getScheme()))
    340331                {
    341332                    newVal = new URL(null, src.toASCIIString(), new Handler());
    342                 } else
    343                 {
    344                     newVal = src.toURL();
    345333                }
    346334
    347                 if (!newVal.equals(imageSrc))
     335                if (newVal != null && !newVal.equals(imageSrc))
    348336                {
    349337                    imageSrc = newVal;
  • trunk/test/unit/org/openstreetmap/josm/tools/ImageProviderTest.java

    r10409 r11526  
    33
    44import static org.junit.Assert.assertEquals;
     5import static org.junit.Assert.assertFalse;
    56import static org.junit.Assert.assertNotNull;
    67
     
    910import java.io.File;
    1011import java.io.IOException;
     12import java.util.logging.Handler;
     13import java.util.logging.LogRecord;
     14import java.util.logging.Logger;
     15
     16import javax.swing.ImageIcon;
    1117
    1218import org.junit.BeforeClass;
     
    1521import org.openstreetmap.josm.TestUtils;
    1622
     23import com.kitfox.svg.SVGConst;
     24
    1725/**
    1826 * Unit tests of {@link ImageProvider} class.
    1927 */
    2028public class ImageProviderTest {
     29
     30    private static final class LogHandler14319 extends Handler {
     31        boolean failed;
     32
     33        @Override
     34        public void publish(LogRecord record) {
     35            if ("Could not load image: https://host-in-the-trusted-network.com/test.jpg".equals(record.getMessage())) {
     36                failed = true;
     37            }
     38        }
     39
     40        @Override
     41        public void flush() {
     42        }
     43
     44        @Override
     45        public void close() throws SecurityException {
     46        }
     47    }
    2148
    2249    /**
     
    5380
    5481    /**
     82     * Non-regression test for ticket <a href="https://josm.openstreetmap.de/ticket/14319">#14319</a>
     83     * @throws IOException if an error occurs during reading
     84     */
     85    @Test
     86    public void testTicket14319() throws IOException {
     87        LogHandler14319 handler = new LogHandler14319();
     88        Logger.getLogger(SVGConst.SVG_LOGGER).addHandler(handler);
     89        ImageIcon img = new ImageProvider(
     90                new File(TestUtils.getRegressionDataDir(14319)).getAbsolutePath(), "attack.svg").get();
     91        assertNotNull(img);
     92        assertFalse(handler.failed);
     93    }
     94
     95    /**
    5596     * Test fetching an image using {@code wiki://} protocol.
    5697     */
Note: See TracChangeset for help on using the changeset viewer.