0

テンプレートの問題のある部分は次のとおりです。

<ul id="list">
  <template iterate='file in convertedfiles.files'>
    <li>{{file.filename}}
    <template if='file.isImage'>
      <img src="{{file.src}}" alt="{{file.filename}}"><br/>
      Source: {{file.src}}
     </template>
    </li>
  </template>
</ul>

ConvertedfilesはAndroidFileのリストです。

class AndroidFile {
File _file;  

String filename;
String src;
bool isImage;

AndroidFile(this._file) : isImage = false {
    filename = htmlEscape(_file.name);

    // If the file is an image, read and display its thumbnail.
    if (_file.type.startsWith('image')) {
    FileReader reader = new FileReader();
    reader.on.load.add((e) {
        src = reader.result.toString().trim();

        // prints the correct URL (data:image/png;base64,...)
        print(src);
        isImage = true;  
        watcher.dispatch();
      });

    reader.readAsDataUrl(_file);  
    }
  }
}

テンプレートが表示されます。ファイル名が表示され、ソースが表示されますが、imagetagは次のようになります。

 <img alt="screenshot-1179.png" src="#"> 

ハッシュには下線が引かれ(Chromiumソースビューで)、クリックすると「ファイルが見つかりません:/ web /out/」と表示されます。

ChromeでJSに変換されると、「リソースは画像として解釈されますが、MIMEタイプtext/htmlで転送されます」と表示されます。

サンプルソースはGitHub
にあり ますヒントはありますか?

4

2 に答える 2

2

XSS に対して脆弱ではない安全な URI を処理していることがわかっている場合は、SafeUri ラッパー (からインポートweb_ui/web_ui.dart) を使用してこの問題を回避できます。たとえば、テンプレートを次のように変更します。

<img src="{{file.src}}" alt="{{file.filename}}">

に:

<img src="{{new SafeUri.unsafe(file.src)}}" alt="{{file.filename}}">

または、file.src を内部的に変更して、SafeUri を格納します。

于 2013-01-02T18:40:59.497 に答える
1

問題を見つけました。

これは、セキュリティ上の理由からURIがサニタイズされるためです。サニタイザーは無効なURIをハッシュに変換します#

差出人web_ui/templating.dart

/**
 * Ensure that [usiString] is a safe URI. Otherwise, return a '#' URL.
 *
 * The logic in this method was based on the GWT implementation located at:
 * http://code.google.com/p/google-web-toolkit/source/browse/trunk/user/src/com/google/gwt/safehtml/shared/UriUtils.java
 */
String sanitizeUri(uri) {
  if (uri is SafeUri) return uri.toString();
  uri = uri.toString();
  return _isSafeUri(uri) ? uri : '#';
}

const _SAFE_SCHEMES = const ["http", "https", "ftp", "mailto"];

bool _isSafeUri(String uri) {
  var scheme = new Uri(uri).scheme;
  if (scheme == '') return true;

  // There are two checks for mailto to correctly handle the Turkish locale.
  //   i -> to upper in Turkish locale -> İ
  //   I -> to lower in Turkish locale -> ı
  // For details, see: http://www.i18nguy.com/unicode/turkish-i18n.html
  return _SAFE_SCHEMES.contains(scheme.toLowerCase()) ||
      "MAILTO" == scheme.toUpperCase();
}

したがって、サニタイザーはdata:スキームURIをに変換し#ます。データURIはXSSに使用できますが、私が知る限り、データURIのコンテンツタイプがであるときにデータURIを許可することで、チェックを改善できる可能性がありますimage/*

おそらくバグレポートを提出しますか?

于 2012-12-31T12:53:13.083 に答える