Changeset 27 in code


Ignore:
Timestamp:
Nov 21, 2016, 10:36:58 PM (9 years ago)
Author:
alex
Message:

Fix #13

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/morty.go

    r26 r27  
    1212        "log"
    1313        "net/url"
     14        "path"
    1415        "regexp"
    1516        "strings"
     
    3132}
    3233
    33 var CSS_URL_REGEXP *regexp.Regexp = regexp.MustCompile("url\\((['\"]?)([\u0009\u0021\u0023-\u0026\u0028\u002a-\u007E]+)(['\"]?)\\)?")
     34var CSS_URL_REGEXP *regexp.Regexp = regexp.MustCompile("url\\((['\"]?)[ \\t\\f]*([\u0009\u0021\u0023-\u0026\u0028\u002a-\u007E]+)(['\"]?)\\)?")
    3435
    3536var UNSAFE_ELEMENTS [][]byte = [][]byte{
     
    382383                                                if bytes.Equal(attr[0], []byte("action")) {
    383384                                                        formURL, _ = url.Parse(string(attr[1]))
    384                                                         formURL = mergeURIs(rc.BaseURL, formURL)
     385                                                        mergeURIs(rc.BaseURL, formURL)
    385386                                                        break
    386387                                                }
     
    526527}
    527528
    528 func mergeURIs(u1, u2 *url.URL) (*url.URL) {
    529         return u1.ResolveReference(u2)
     529func mergeURIs(u1, u2 *url.URL) {
     530        if u2.Scheme == "" || u2.Scheme == "//" {
     531                u2.Scheme = u1.Scheme
     532        }
     533        if u2.Host == "" && u1.Path != "" {
     534                u2.Host = u1.Host
     535                if len(u2.Path) == 0 || u2.Path[0] != '/' {
     536                        u2.Path = path.Join(u1.Path[:strings.LastIndexByte(u1.Path, byte('/'))], u2.Path)
     537                }
     538        }
    530539}
    531540
    532541func (rc *RequestConfig) ProxifyURI(uri string) (string, error) {
    533         // remove javascript protocol
    534         if strings.HasPrefix(uri, "javascript:") {
    535                 return "", nil
    536         }
    537542        // TODO check malicious data: - e.g. data:script
    538543        if strings.HasPrefix(uri, "data:") {
     
    548553                return "", err
    549554        }
    550         u = mergeURIs(rc.BaseURL, u)
     555        mergeURIs(rc.BaseURL, u)
    551556
    552557        uri = u.String()
Note: See TracChangeset for help on using the changeset viewer.