SharePoint Online テナントのほとんどは、strict モデルを使用してファイル オープン エクスペリエンスを処理します。 その結果、問題を起こす可能性のあるすべてのファイル (埋め込みスクリプトがある html ファイルなど) はブラウザーでは実行されず、未処理のコンテンツ (最新のユーザー エクスペリエンスでは html プレビュー) としてダウンロードまたは表示されます。 テナントが permissive モデルを使用して構成されている場合、ファイル オープン エクスペリエンスはファイルを実行します。たとえば、ドキュメント ライブラリ内の html ファイルが実行され、ページがブラウザーに表示されます。 strict に設定されている場合、このファイルはダウンロードされます。
現在の既定の設定は strict となっており、テナントの設定を permissive モデルに切り替えることはできません。 過去に permissive に切り替えたテナントについては、今後状況が変わる予定です。permissive モデルのテナントは 2018 年末までに非推奨となり、それらのテナントはすべて strict に切り替えられることになります。
重要
2018 年 12 月 31 日の時点で permissive モデルを使用しているすべてのテナントは strict モデルに切り替えられます。
使用しているテナントへの影響
SharePoint Online 用の Office 365 PowerShell を使用して PermissiveBrowserFileHandlingOverride の設定を確認することが推奨されています。
Connect-SPOService -url https://contoso-admin.sharepoint.com
$tenant = get-spotenant
$tenant.PermissiveBrowserFileHandlingOverride
設定が False の場合は、テナントへの影響はありません。設定が True になっている場合は、今後の廃止に備える必要があります。
permissive から strict への変更への準備
手順 1: 影響を評価する
まず、影響を受けるファイルを確認することが重要です。permissive ファイルのスキャナーでこれを行うことができます。 スキャナーとその使用方法の詳細については、「SharePoint Permissive Scanner」を参照してください。 既定の構成では、このスキャナーは html ファイルまたは htm ファイルを検索しますが、コマンド ライン オプションを使用すると、このスキャナーで他のファイルの種類を検索することができます。
スキャンの結果は、html または htm ファイルに関する情報 (使用されているリンクとスクリプトの数、最終変更データ、参照回数) を含む、影響を受けたすべてのファイル (html、htm、オプションで他のファイルの種類) をリストにした CSV ファイルで確認することができます。
手順 2: スキャンの結果を分析する
影響を受けたファイルのリストを取得したら、これらのファイルとこれらのファイルを保持するサイトがまだビジネスに関連しているかどうかを判断する必要があります。 ファイルやサイトが古くなっている場合があり、そのようなファイルやサイトの修復はスキップされる可能性があります。 ビジネス ニーズの理解に役立つように、レポートにはサイト コレクションの管理者とサイト所有者の情報が含まれており、また連絡先もそのレポートで確認することができます。
手順 3: ファイルを修復する
ファイルが依然として重要で、テナントが strict の設定に移動した後でもファイルを実行できるようにする場合は、次の章で説明するように、ファイルを修復する必要があります。
html ファイルまたは htm ファイルの修復プロセス
permissive モードを継続するお客様の主な理由として、ドキュメント ライブラリ内からの html ファイルの使用を可能にしたいということが挙げられます。 前述のように、いったん strict に移動したファイルはダウンロードされるのみで、自動的には開きません。
これらの html ファイルまたは htm ファイルの修復は簡単です。html ファイルまたは htm ファイルの名前が、サイト所有者やサイト コレクションの管理者のアクセス許可を持つユーザーまたはアプリケーションによって ASPX ファイルに変更されると、これらのファイルを再度開くことができます。
SharePoint PnP PowerShell の下に、これを実行する方法を示しています。 次の URL を含むファイルがあるとします: https://contoso.sharepoint.com/sites/permissive/html/newfile.html
。
Connect-PnPOnline -Url https://contoso.sharepoint.com/sites/permissive -Verbose
Rename-PnPFile -ServerRelativeUrl /sites/permissive/html/newfile.html -TargetFileName newfile.aspx -OverwriteIfAlreadyExists
注:
PnP PowerShell はオープン ソース ソリューションであり、アクティブなコミュニティでサポートが提供されています。 Microsoft からのオープン ソース ツールのサポート SLA はありません。
サイト コレクション全体の完全な "修復" を実行できるスクリプトについても後述します。
名前の変更を行えるユーザー
名前の変更は、既定でサイト コレクションの管理者またはサイト所有者に付与されている、AddAndCustomizePages (ACP) のアクセス許可を持つユーザーが実行する必要があります。 名前の変更が編集アクセス許可レベルを持つユーザー (サイトのメンバー) によって行われた場合、ファイルの名前は変更されますが、変更後の .aspx ファイルは実行用にマーク付けされません。そのため、ファイルはダウンロードされますが、実行はされません。
一括して名前を変更するには、ユーザー アカウントではなくアプリ プリンシパルを使用することが多いですが、その場合も同じ点が当てはまります。これを行うには、ACP のアクセス許可 (フル コントロールのアクセス権限レベル) が必要です。
その他の html ファイルまたは htm ファイルへの埋め込みリンクについて
html ファイルまたは htm ファイルが、同じフォルダーまたはサブフォルダー内の他の html ファイルまたは htm ファイルにリンクしています。ファイルの名前が aspx に変更された場合、これらのリンクは無効になるのでしょうか? 基になる名前の変更が MoveTo API を呼び出して行われた場合、html ファイル内の相対リンクのほとんどが、自動的に aspx ファイルへのリンクに修正されます。基本的に、実際のファイルの名前を変更するだけで、相互にリンクしている入れ子になった html ファイルまたは htm ファイルの構造の名前を変更することができます。ドキュメント内のすべてのリンクは、名前の変更によって処理されます。
注:
html ドキュメントに別のサイト コレクション内のファイルを指すリンクがある場合、または JavaScript を使用してリンクが動的に生成される場合、自動的な名前の変更は行われません。 そのような場合は、手動による操作でリンクを修正する必要があります。
コンテンツ エディター Web パーツで参照される html ファイルまたは htm ファイルについて
コンテンツ エディター Web パーツで作業する場合の一般的なパターンでは、html ファイルまたは htm ファイルが参照されます。 参照先の html ファイルまたは htm ファイルの名前が .aspx ファイルに変更されると、SharePoint によってコンテンツ エディター Web パーツの参照も自動的に更新されます。つまり、このとき以降、コンテンツ エディター Web パーツが html ファイルまたは htm ファイルではなく、.aspx ファイルを読み込みます。 このため、コンテンツ エディター Web パーツで使用されるファイルであれば、他のすべての html ファイルおよび htm ファイルと同様に名前を変更することができます。
“noscript” 機能が有効になっているサイトについて
既定では、すべての “モダン” サイト (モダン チーム サイト、コミュニケーション サイト) で “noscript” 機能がオンになっています。 その結果、誰も AddAndCustomizePages (ACP) のアクセス許可を持たないため、html または htm から aspx への名前の変更を正常に行うことができません。 通常、html ファイルまたは htm ファイルは、(移行された) クラシック チーム サイトにあるので、そこではこの問題は発生しません。 “noscript” のサイトで作業をしている場合は、まず “noscript” をオフにし、その後に名前の変更を実施して、再度 “noscript” をオンにしてください。 そうすると、html ファイルまたは htm ファイルを再び実行することができます。ただし、これらのファイルに変更を加えるたびに実行不可として再びマーク付けされるわけではありません。 “noscript” をオフにしてファイルを更新すれば、この問題に対処できます。
最新のドキュメント ライブラリ エクスペリエンスで、aspx ファイルは最初は閉じられたままなのでしょうか?
最新のドキュメント ライブラリ エクスペリエンスでは、ファイルが追加されたときに特定のファイルの種類が “想定” されます。初めてファイルにアクセスすると、aspx ファイルが誤って開かれることがあります。 ただし、2 回目にアクセスを試みると、ファイルが実行されます。 この問題を回避するには、名前を変更した各ファイルをプログラムでいったん引き出し、SharePoint にファイルの種類を正しく設定する機会を与えることが推奨されます。 SharePoint PnP PowerShell の下に、これを実行する方法を示しています。
Connect-PnPOnline -Url https://contoso.sharepoint.com/sites/permissive -Verbose
Get-PnPFile -Url /sites/permissive/html/newfile.aspx -Path c:\temp -Filename newfile.aspx -AsFile
注:
この "ダウンロード" 手順は、サイト コレクション全体の完全な "修復" を実行できるスクリプトに含まれます。
その他のファイルの種類の修復
permissive モードを使用する主な理由として、html ファイルまたは htm ファイルが挙げられますが、他のファイルの種類についてはどうなのでしょうか? このブログで説明しているように、多くの共通のファイル形式に対して SharePoint Online はプレビュー機能を提供しています。 SharePoint Online は次の形式のプレビューができます。
ドキュメント
csv、doc、docm、docx、dotx、eml、msg、odp、ods、odt、pdf、pot、potm、potx、pps、ppsx、ppt、pptm、pptx、rtf、vsd、vsdx、xls、xlsb、xlsm、xlsx
画像
ai、arw、bmp、cr2、eps、erf、gif、ico、icon、jpeg、jpg、mrw、nef、orf、pict、png、psd、tif、tiff
ビデオ
3gp、m4v、mov、mp4、wmv
3D
3mf、fbx、obj、ply、stl
医療
dcm、dcm30、dic、dicm、dicom
テキストとコード
abap、ada、adp、ahk、as、as3、asc、ascx、asm、asp、awk、bash、bash_login、bash_logout、bash_profile、bashrc, bat、bib、bsh、build、builder、c、c++、capfile、cc、cfc、cfm、cfml、cl、clj、cls、cmake、cmd、coffee、cpp、cpt、cpy、cs、cshtml、cson、csproj、css、ctp、cxx、d、ddl、di、dif、diff、disco、dml、dtd、dtml、el、emakefile、erb、erl、f、f90、f95、fs、fsi、fsscript、fsx、gemfile、gemspec、gitconfig、go、groovy、gvy、h、h++、haml、handlebars、hbs、hcp、hh、hpp、hrl、hs、htc、hxx、idl、iim、inc、inf、ini、inl、ipp、irbrc、jade、jav、java、js、jsp、jsx、l、less、lhs、lisp、log、lst、ltx、lua、m、make、markdn、markdown、md、mdown、mkdn、ml、mli、mll、mly、mm、mud、nfo、opml、osascript、out、p、pas、patch、php、php2、php3、php4、php5、phtml、pl、plist、pm、pod、pp、profile、properties、ps1、pt、py、pyw、r、rake、rb、rbx、rc、re、readme、reg、rest、resw、resx、rhtml、rjs、rprofile、rpy、rss、rst、rxml、s、sass、scala、scm、sconscript、sconstruct、script、scss、sgml、sh、shtml、sml、sql、sty、tcl、tex、text、textile、tld、tli、tmpl、tpl、txt、vb、vi、vim、wsdl、xhtml、xml、xoml、xsd、xsl、xslt、yaml、yaws、yml、zip、zsh
サイト コレクション全体を修復できるサンプル スクリプト
このスクリプトは、サイト コレクション スコープの修復のための開始基準として使用することができます。 このスクリプトにより、以下の処理が実行されます。
- PnP-PowerShell をインストールする (まだインストールされていない場合)
- 検索を使用して、サイト コレクション内のすべての html ファイルおよび htm ファイルを検索する
- それらのファイル名を .aspx に変更する
- 名前の変更されたファイルをダウンロードして、最新ドキュメント ライブラリのユーザー インターフェイスでの初回アクセスで動作するようにする
# This script does rename .htm and .html files to .aspx files. Doing so enables these files to be "executed" in SharePoint Online
# which has it's file handling configured to be strict. See https://learn.microsoft.com/sharepoint/dev/solution-guidance/security-permissivesetting
# for more details
function PermissiveRemediateASiteCollection
{
param([string] $siteCollectionUrl, [string] $winCredentialsManagerLabel)
$siteCollectionUrl = $siteCollectionUrl.TrimEnd("/");
# Gets or Sets the tenant admin credentials.
$credentials = $null
if(![String]::IsNullOrEmpty($winCredentialsManagerLabel) -and (Get-PnPStoredCredential -Name $winCredentialsManagerLabel) -ne $null)
{
$credentials = $winCredentialsManagerLabel
}
else
{
# Prompts for credentials, if not found in the Windows Credential Manager.
$email = Read-Host -Prompt "Please enter admin email"
$pass = Read-host -AsSecureString "Please enter admin password"
$credentials = New-Object –TypeName "System.Management.Automation.PSCredential" –ArgumentList $email, $pass
}
if($credentials -eq $null)
{
Write-Host "Error: No credentials supplied." -ForegroundColor Red
exit 1
}
Connect-PnPOnline -Url $siteCollectionUrl -Credentials $credentials -Verbose
Write-Host "Using search to obtain a list of files to remediate..."
Try
{
$searchQuery = "((fileextension=htm OR fileextension=html) AND contentclass=STS_ListItem_DocumentLibrary AND Path:$siteCollectionUrl/*)"
$htmlFiles = Submit-PnPSearchQuery -Query $searchQuery -TrimDuplicates:$false -All
}
Catch [Exception]
{
$ErrorMessage = $_.Exception.Message
Write-Host "Error: Search query to find the files to remediate failed...exiting the script" -ForegroundColor Red
Write-Host "Error: $ErrorMessage" -ForegroundColor Red
exit 1
}
# if no files were found then bail out
if ($htmlFiles.RowCount -eq 0)
{
Write-Host "No files found to remediate...exiting the script" -ForegroundColor Green
exit 0
}
else
{
Write-Host "Found" $htmlFiles.RowCount "files to remediate" -ForegroundColor Green
}
# Create temp folder if not yet existing
$path = "$env:TEMP\permissivefix"
If(!(test-path $path))
{
New-Item -ItemType Directory -Force -Path $path
}
# iterate over the found files and rename them
foreach($htmlFile in $htmlFiles.ResultRows)
{
Try
{
$web = $htmlFile.SPWebUrl
Write-Host "Connected to $web..."
Connect-PnPOnline -Url $web -Credentials $credentials
$fileToRename = $htmlFile.OriginalPath
Write-Host "Renaming $fileToRename..."
# Get the server relative path
$serverRelativePath = $fileToRename.Replace("https://", "")
$serverRelativePath = $serverRelativePath.Substring($serverRelativePath.IndexOf("/"))
#Write-Host $serverRelativePath
# Get new file name and server relative path
$newFileName = $serverRelativePath.Substring($serverRelativePath.LastIndexOf("/") + 1).ToLower()
$serverRelativePathNew = $serverRelativePath
if ($newFileName.EndsWith(".html"))
{
$newFileName = $newFileName.Replace(".html", ".aspx")
$serverRelativePathNew = $serverRelativePathNew.Replace(".html", ".aspx")
}
elseif($newFileName.EndsWith(".htm"))
{
$newFileName = $newFileName.Replace(".htm", ".aspx")
$serverRelativePathNew = $serverRelativePathNew.Replace(".html", ".aspx")
}
# Perform the file rename
Rename-PnPFile -ServerRelativeUrl $serverRelativePath -TargetFileName $newFileName -OverwriteIfAlreadyExists -Force
# Download the file once to ensure it works correctly in modern UI
Get-PnPFile -Url $serverRelativePathNew -Path $path -Filename $newFileName -AsFile -Force
}
Catch [Exception]
{
$ErrorMessage = $_.Exception.Message
Write-Host "Error: Rename of file $serverRelativePath failed" -ForegroundColor Red
Write-Host "Error: $ErrorMessage" -ForegroundColor Red
}
}
# Cleanup the temp folder
Write-Host "Cleaning up the temp folder $path"
Remove-Item $path -Recurse -ErrorAction Ignore
Write-Host "Remediation done for site collection $siteCollectionUrl" -BackgroundColor DarkGreen -ForegroundColor White
}
#######################################################
# MAIN section #
#######################################################
# Url of the site collection to remediate
$siteCollectionUrlToRemediate = "https://contoso.sharepoint.com/sites/testsite"
# If you use credential manager then specify the used credential manager entry, if left blank you'll be asked for a user/pwd
$credentialManagerCredentialToUse = "credmandreference"
# Ensure PnP PowerShell is loaded
if (-not (Get-Module -ListAvailable -Name SharePointPnPPowerShellOnline))
{
Install-Module SharePointPnPPowerShellOnline
}
Import-Module SharePointPnPPowerShellOnline
# Remediate the given site collection
PermissiveRemediateASiteCollection $siteCollectionUrlToRemediate $credentialManagerCredentialToUse
スクリプト実行が成功した場合の出力例は次のようになります。
WARNING: The names of some imported commands from the module 'SharePointPnPPowerShellOnline' include unapproved verbs that might make them less discoverable. To find the commands with unapproved ver
bs, run the Import-Module command again with the Verbose parameter. For a list of approved verbs, type Get-Verb.
VERBOSE: PnP PowerShell Cmdlets (2.22.1801.0): Connected to https://contoso.sharepoint.com/sites/testsite
Using search to obtain a list of files to remediate...
Found 15 files to remediate
Directory: C:\Users\demouser\AppData\Local\Temp
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 7/02/2018 19:48 permissivefix
Connected to https://contoso.sharepoint.com/sites/testsite...
Renaming https://contoso.sharepoint.com/sites/testsite/Shared Documents/About.html...
Connected to https://contoso.sharepoint.com/sites/testsite...
Renaming https://contoso.sharepoint.com/sites/testsite/Shared Documents/brol.html...
Connected to https://contoso.sharepoint.com/sites/testsite...
Renaming https://contoso.sharepoint.com/sites/testsite/Shared Documents/imagetarget.html...
Connected to https://contoso.sharepoint.com/sites/testsite...
Renaming https://contoso.sharepoint.com/sites/testsite/Shared Documents/sample_html_afternoscript9.html...
Connected to https://contoso.sharepoint.com/sites/testsite...
Renaming https://contoso.sharepoint.com/sites/testsite/Shared Documents/bla.html...
Connected to https://contoso.sharepoint.com/sites/testsite...
Renaming https://contoso.sharepoint.com/sites/testsite/Shared Documents/sample_html.html...
Connected to https://contoso.sharepoint.com/sites/testsite...
Renaming https://contoso.sharepoint.com/sites/testsite/Shared Documents/home2.html...
Connected to https://contoso.sharepoint.com/sites/testsite...
Renaming https://contoso.sharepoint.com/sites/testsite/Shared Documents/howtouse.html...
Connected to https://contoso.sharepoint.com/sites/testsite...
Renaming https://contoso.sharepoint.com/sites/testsite/Shared Documents/home.html...
Connected to https://contoso.sharepoint.com/sites/testsite...
Renaming https://contoso.sharepoint.com/sites/testsite/Shared Documents/team_home.html...
Connected to https://contoso.sharepoint.com/sites/testsite...
Renaming https://contoso.sharepoint.com/sites/testsite/Shared Documents/imagesource.html...
Connected to https://contoso.sharepoint.com/sites/testsite...
Renaming https://contoso.sharepoint.com/sites/testsite/Shared Documents/bla2.html...
Connected to https://contoso.sharepoint.com/sites/testsite...
Renaming https://contoso.sharepoint.com/sites/testsite/Shared Documents/wikipage.html...
Connected to https://contoso.sharepoint.com/sites/testsite...
Renaming https://contoso.sharepoint.com/sites/testsite/Shared Documents/newfile_html.html...
Connected to https://contoso.sharepoint.com/sites/testsite...
Renaming https://contoso.sharepoint.com/sites/testsite/Shared Documents/Home3.html...
Cleaning up the temp folder C:\Users\demouser\AppData\Local\Temp\permissivefix
Remediation done for site collection https://contoso.sharepoint.com/sites/testsite