|
| 1 | +/* Configuration.scala - Library to protect agains SSRF. |
| 2 | + * Pull requests are welcome, please find this tool hosted on http://github.com/IncludeSecurity |
| 3 | + * |
| 4 | + * The MIT License (MIT) |
| 5 | + * |
| 6 | + * Copyright (c) 2014 Samuel Groß |
| 7 | + * Copyright (c) 2014 Include Security <info [at sign] includesecurity.com> |
| 8 | + * |
| 9 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 10 | + * of this software and associated documentation files (the "Software"), to deal |
| 11 | + * in the Software without restriction, including without limitation the rights |
| 12 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 13 | + * copies of the Software, and to permit persons to whom the Software is |
| 14 | + * furnished to do so, subject to the following conditions: |
| 15 | + * |
| 16 | + * The above copyright notice and this permission notice shall be included in |
| 17 | + * all copies or substantial portions of the Software. |
| 18 | + * |
| 19 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 20 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 21 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 22 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 23 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 24 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 25 | + * THE SOFTWARE. |
| 26 | + */ |
| 27 | + |
| 28 | +package com.includesecurity.safeurl |
| 29 | + |
| 30 | + |
| 31 | +/** Access lists for the various parts of a URL. */ |
| 32 | +class AccessList { |
| 33 | + var whitelist: List[String] = Nil |
| 34 | + var blacklist: List[String] = Nil |
| 35 | +} |
| 36 | + |
| 37 | +/** Contains an AccessList for each part of the URL that is validated. */ |
| 38 | +class ListContainer { |
| 39 | + var ip: AccessList = new AccessList |
| 40 | + var port: AccessList = new AccessList |
| 41 | + var domain: AccessList = new AccessList |
| 42 | + var protocol: AccessList = new AccessList |
| 43 | +} |
| 44 | + |
| 45 | +/** SafeURL configuration. |
| 46 | + * |
| 47 | + * Stores the black- and whitelists used by SafeURL as well |
| 48 | + * as some other configuration properties. |
| 49 | + * |
| 50 | + * Has secure defaults. |
| 51 | + */ |
| 52 | +class Configuration { |
| 53 | + /** Do secure redirects, revalidate each redirect location first. */ |
| 54 | + var secureRedirects: Boolean = true |
| 55 | + |
| 56 | + /** The maximum number of redirects SaveCurl will follow. */ |
| 57 | + var maxRedirects: Int = 20 |
| 58 | + |
| 59 | + /** Determines whether SafeURL will pin DNS entries, preventing DNS rebinding attacks. */ |
| 60 | + var pinDNS: Boolean = true |
| 61 | + |
| 62 | + /** When a protocol is allowed also allow its default port. */ |
| 63 | + var allowDefaultPort: Boolean = true |
| 64 | + |
| 65 | + /** Access lists for the various parts of a URL. */ |
| 66 | + var lists: ListContainer = Configuration.defaultAccessLists |
| 67 | +} |
| 68 | + |
| 69 | +object Configuration { |
| 70 | + def defaultAccessLists: ListContainer = { |
| 71 | + val lists = new ListContainer |
| 72 | + lists.ip.blacklist = "0.0.0.0/8" :: |
| 73 | + "10.0.0.0/8" :: |
| 74 | + "100.64.0.0/10" :: |
| 75 | + "127.0.0.0/8" :: |
| 76 | + "169.254.0.0/16" :: |
| 77 | + "172.16.0.0/12" :: |
| 78 | + "192.0.0.0/29" :: |
| 79 | + "192.0.2.0/24" :: |
| 80 | + "192.88.99.0/24" :: |
| 81 | + "192.168.0.0/16" :: |
| 82 | + "198.18.0.0/15" :: |
| 83 | + "198.51.100.0/24" :: |
| 84 | + "203.0.113.0/24" :: |
| 85 | + "224.0.0.0/4" :: |
| 86 | + "240.0.0.0/4" :: |
| 87 | + Nil |
| 88 | + |
| 89 | + lists.port.whitelist = "80" :: "8080" :: "443" :: Nil |
| 90 | + lists.protocol.whitelist = "http" :: "https" :: Nil |
| 91 | + |
| 92 | + lists |
| 93 | + } |
| 94 | +} |
0 commit comments